Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

How to iterate child objects
Started by Painconfess Jan 09 2016 03:49 AM

2 replies to this topic

Best Answer Caleb P , 10 January 2016 - 05:20 AM

Feel free to modify the host objects, just don't delete them or move them into another group.

 

What I do is add a "hostObject" and "builtObject" property to the objects I build and the host objects, then I can access either object when I have access to one of them. So to iterate through each built object, you'd just do a for object in map.layer["layer"].objects() do and access the object.builtObject.

 

- Caleb

[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Painconfess

[GLOBAL: userInfoPane.html]
Painconfess
  • Enthusiast

  • 49 posts
  • Corona SDK

for object in map.layer["objects"].objects()

Seems only iterate the host objects. I need to iterate all built child objects for pausing the game. First I was thinking to make host object pause and resume function for the child object, but then I remembered you saying not to modify host objects. 

 



[TOPIC: post.html]
#2

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,585 posts
  • Corona SDK

I'm pretty sure those are display groups.

 

https://docs.coronalabs.com/daily/api/type/GroupObject/index.html

local group = display.newGroup()

display.newCircle( group, 10, 10, 10 )
print( "Group contains: ", group.numChildren ) -- "Group contains: 1"

display.newCircle( group, 10, 10, 10 )
print( "Group contains: ", group.numChildren ) -- "Group contains: 2"

display.newCircle( group, 10, 10, 10 )
print( "Group contains: ", group.numChildren ) -- "Group contains: 3"


for i = 1, group.numChildren do
-- something here
end


[TOPIC: post.html]
#3

Caleb P

[GLOBAL: userInfoPane.html]
Caleb P
  • Corona Geek

  • 1,424 posts
  • Corona SDK

  Best Answer

Feel free to modify the host objects, just don't delete them or move them into another group.

 

What I do is add a "hostObject" and "builtObject" property to the objects I build and the host objects, then I can access either object when I have access to one of them. So to iterate through each built object, you'd just do a for object in map.layer["layer"].objects() do and access the object.builtObject.

 

- Caleb




[topic_controls]
[/topic_controls]