display.newImageRect parameters update?

Hi,

Is it possible to update the parameters of an object which is a display.newImageRect ?

I have nested displayGroups with these objects which have a lot properties. So the way I do it now is removing the object from the displayGroup and reinsert it with new parameters (and properties like object.x for position). This feels kinda clumsy and needs to much code imo.

The properties can be updated easily by accessing the displaygroup like
[lua]myGroup[line][letterImage].x = myGroup[line][letterImage].x + 30[/lua]
But how could the parameters be updated?

To be clear I mean these parameters :
[lua]object = display.newImageRect( [parentGroup,] filename [, baseDirectory] width, height )[/lua]

thx [import]uid: 148841 topic_id: 29602 reply_id: 329602[/import]

You can change the width and height using .width and .height, though that will see cropping - scaling would also work.

For changing the image source parameter no, you’d have to remove and re-add the image. [import]uid: 52491 topic_id: 29602 reply_id: 118856[/import]

I’m not 100% sure I fully understand your question. But let me try anyway.

None of the passed parameters to display.newImageRect() are things that can be changed. For instance, if you change the file name, you’re referencing a different image so it’s really only used at image load time. Like wise the basedirectory is used to find the file, there is no reason to change that after it’s loaded. That leaves group and the two size parameters. The two size parameters are used to load the initial image. You probably could change the width and height after the fact, but I’m not sure what the effect would be:

pic = display.newImageRect(“pic.png”, 100, 150)

pic.width = 75

**MAY** change the width, but the best way to do it is using the scale method:

pic:scale(0.5, 0.5)

would make the above pic a 50x75 (50% height and width)

That leaves the group. If you want to move it from one group to another, just insert it into the new group and Corona will remove it from the old group for you. Things can only be in one group at a time.

[import]uid: 19626 topic_id: 29602 reply_id: 118866[/import]

Hi Peach, Rob,

Thanks for your answers. I was indeed aiming at updating the image source parameters. Probably the image gets cached?

Would it be possible if you use an imagesheet to update the framenumber parameter in a display.newImageRect object?

I just wonder what the best way is to change an image or animate an object which is stuffed in a group.

[import]uid: 148841 topic_id: 29602 reply_id: 119004[/import]

Simply changing the image course for display.newImageRect() isn’t possible without removing and re-adding the image - you could you only use an image sheet/sprite to change an image easily but not using newImageRect, only sprite API. [import]uid: 52491 topic_id: 29602 reply_id: 119018[/import]