In my game, I am adding one display object as child of another as below
[lua]local art = sprite.newSprite(artSet) --This being main display object
art.sensor = display.newCircle(art.x,art.y,100) – This being attached object which is a sensor object to implement “attack” range for art object.[/lua]
However, when I add collision handler for art.sensor above and user e.target.parent, I don’t get art object but rather global display group object of which every display object is part of.
I guess this boils down to how to get parent table when we have handle to a child element of that table.
Any clues? [import]uid: 48521 topic_id: 10933 reply_id: 310933[/import]
In your creation for the art.sensor object you haven’t passed in a displayGroup which means it gets added to the current stage.
-- Adds to the global stage
local sensor = display.newCircle( art.x, art.y, 100 )
[code]
– Adds to the local group
local group = display.newGroup()
local sensor = display.newCircle( group, art.x, art.y, 100 )
– The sensor parent is now “group”
[/code] [import]uid: 5833 topic_id: 10933 reply_id: 39791[/import]
To add to the above now you have sensor added to the group you can reference to it as group.sensor or you can simplify to group.sensor = sensor and just use sensor again
[import]uid: 33866 topic_id: 10933 reply_id: 39811[/import]
No, that’s not what I want.
I know how to use display groups.
What I am doing is just adding one display object as property of another. Or in LUA terms, making one table as a element of another. (as display objects are just tables in reality)
[import]uid: 48521 topic_id: 10933 reply_id: 39889[/import]
Setting “art.sensor” as a display object is yes, as you say, adding the object as a property of the other however it does not make “art” the parent of “sensor”. Is this what you are trying to do?
– edit -
Or are you trying to find a more generic Lua way of finding the parent table regardless of Corona etc? If so, might get a better response in the Lua Language subforum - http://developer.anscamobile.com/forum/11 [import]uid: 5833 topic_id: 10933 reply_id: 39890[/import]
Thanks… I ended up asking ppl in IRC #lua channel…
I was indeed trying to find a more generic Lua way of finding the parent table regardless of Corona.
According to ppl there, I have to store reference to parent within the child to get handle back to parent. [import]uid: 48521 topic_id: 10933 reply_id: 39915[/import]
Ah right yea that would do it, shame there isn’t a more inbuilt way but that is easy enough. [import]uid: 5833 topic_id: 10933 reply_id: 39930[/import]