get Object from the displayGroup

Hi guys,

Can anybody please tell me how to get a displayObject from the group, from a particular index.
suppose i added some images to any displayGroup. after the addition, if i want to change the position of particular object in the group, then how to do that.

please help me.

Thanks
[import]uid: 163563 topic_id: 31966 reply_id: 331966[/import]

you can always access every object attribute, even if the object is inside a group

local dGroup = display.newGroup() local rect = display.newRect(dGroup, 0, 0, 100, 100) print ("rect.x, rect.y : "..rect.x.." / ".. rect.y ) rect.x, rect.y = 200, 200 print ("rect.x, rect.y : "..rect.x.." / ".. rect.y ) [import]uid: 70635 topic_id: 31966 reply_id: 127434[/import]

As far as changing the position of an object in a group, you can simply use the remove() and insert() methods:

 local obj1 = aGroup:remove(1)  
 local obj2 = aGroup:remove(1)  
  
 aGroup:insert( obj2 )   
 aGroup:insert( obj1 )   

In the above code, I have a group with two objects. I use remove and insert to swap their positions.

Of course, I could have written the example more simply like this:

 local obj1 = aGroup:remove(1) -- Remove obj from position 1  
 aGroup:insert( obj1 ) -- Put at end of group (last position)  

Lastly, if you want to reference an object that is in a group you can simply do this:

 aGroup[2].x = 100 -- Change x attribute of object in 'aGroup' at position 2 to 100  

http://developer.coronalabs.com/reference/index/groupremove
http://developer.coronalabs.com/reference/index/groupinsert

Cheers,
Ed
Roaming Gamer, LLC.
SSK for Corona SDK (github) (videos) [import]uid: 110228 topic_id: 31966 reply_id: 127485[/import]

you can always access every object attribute, even if the object is inside a group

local dGroup = display.newGroup() local rect = display.newRect(dGroup, 0, 0, 100, 100) print ("rect.x, rect.y : "..rect.x.." / ".. rect.y ) rect.x, rect.y = 200, 200 print ("rect.x, rect.y : "..rect.x.." / ".. rect.y ) [import]uid: 70635 topic_id: 31966 reply_id: 127434[/import]

As far as changing the position of an object in a group, you can simply use the remove() and insert() methods:

 local obj1 = aGroup:remove(1)  
 local obj2 = aGroup:remove(1)  
  
 aGroup:insert( obj2 )   
 aGroup:insert( obj1 )   

In the above code, I have a group with two objects. I use remove and insert to swap their positions.

Of course, I could have written the example more simply like this:

 local obj1 = aGroup:remove(1) -- Remove obj from position 1  
 aGroup:insert( obj1 ) -- Put at end of group (last position)  

Lastly, if you want to reference an object that is in a group you can simply do this:

 aGroup[2].x = 100 -- Change x attribute of object in 'aGroup' at position 2 to 100  

http://developer.coronalabs.com/reference/index/groupremove
http://developer.coronalabs.com/reference/index/groupinsert

Cheers,
Ed
Roaming Gamer, LLC.
SSK for Corona SDK (github) (videos) [import]uid: 110228 topic_id: 31966 reply_id: 127485[/import]