- Variable names are just references (links) so they aren’t preserved in a displayGroup.
[code]local group = display.newGroup()
local monster = display.newImage(group, “dude.png”)
– you can now refer to this object as either “monster” or “group[1]”.
– if you want to keep the name you have to do this…
local group = display.newGroup()
group.monster = display.newImage(group, “dude.png”)
– in this example both “group.monster” and “group[1]” work, but “monster” does not.[/code]
The method you used works also, but it’s another step and arguably is more work to deal with.
- display objects are both displayObjects and tables {}. This includes displayGroups.
[code]local bird = display.newGroup()
bird.beak = display.newImage(“yellowbeak.png”) – this object is not part of the displayGroup!
bird.wing = display.newImage(bird, “bluewing.png”) – this object IS part of the displayGroup!
bird.x = 300 – both bird and bird.wing will move here, but beak will not[/code]
This is because the (optional) first argument of (almost) any displayObject is the group to insert it into. You have to be somewhat careful in that there are a few basic .words that are inherent to displayGroups (visual might be one of them? not sure) but generally speaking you can treat displayGroups as tables.
Keep in mind, though, that displayGroups don’t really have a position until they have objects in them (the size and position is determined by everything it contains, as if you drew a giant box around the contained objects). So usually what you would do is (1) insert all of the objects you want into bird, (2) move the bird components to the right relative positions, and finally (3) move the bird. [import]uid: 41884 topic_id: 34775 reply_id: 140543[/import]