Using Director class: Order of objects

Hi All,

Director Class works well for my first game. Not sure if this is a question of how Corona works or if it’s even related to Director Class.

I have 3 objects, and I insert all of them into the localGroup.

  • A background. This works ok, everything appear on top of this.
  • An animation using a spritesheet, meant to be part of the background. This appears on top of the background ok.
  • A moving object (like a floating balloon) using tween and physics. The problem is that this object appears under the animated sprite when it floats up.

How do I make the object the top layer so it floats over the sprite animation? What controls the layer’s order?

If it’s not related to the Director Class, would appreciate someone pinting me in the right direction.

Thanks
fly [import]uid: 108015 topic_id: 19198 reply_id: 319198[/import]

the order is this:

background=display.newGroup()  
backanimation=display.newGroup()  
objectballon=display.newGroup()  
  
-- insert background on background   
-- insert the animation in backanimation group  
-- insert the ballon in the objectballon group  
  
-- now insert in the principal scene group (local group) the groups in order  
  
localgroup:insert(background)  
localgroup:insert(animation)  
localgroup:insert(ballon)  
  

If you want to control the objects front and back, insert the objects in one group and control with:

object1:toFront()
object2:toBack() [import]uid: 55808 topic_id: 19198 reply_id: 74054[/import]

OK Thanks Jose2. I did insert them in that order. Will try the toFront() tonight. [import]uid: 108015 topic_id: 19198 reply_id: 74061[/import]

Note that inserting an object into a group it’s already in puts said object on top of all other objects.

So:

group:insert(obj1)
group:insert(obj2)
group:insert(obj3)
group:insert(obj1)

=

— obj1 (top layer)
— obj3
— obj2 (bottom layer)

Ch. [import]uid: 4958 topic_id: 19198 reply_id: 74072[/import]

OK I know where the problem is, but I do not know the answer.

I have localGroup()

Then I insert background, so this is the bottom order.

Then I have instance1 as an animation using spritesheet, but I do not have an insert. I have localGroup.instance1:play()

Then I have insert(obj1). This obj1 is above the background correctly, but it’s not above instance1. Have to do a bit more studying to see how I insert a spritesheet into the localGroup.

Thanks
fly [import]uid: 108015 topic_id: 19198 reply_id: 74279[/import]

Hi

Maybe you can try using more than one group. Localgroup could where the background reside. The object could be set into another group (objGroup) and then insert objGroup into localGroup.

I am not too familiar with sprite sheet but could you not insert them into their own group?

Mo [import]uid: 49236 topic_id: 19198 reply_id: 74341[/import]

@lemsim: Thanks for the suggestion. I did try to insert the spritesheet into the group, but that didn’t seem to change anything, or I’m not doing it corretly. [import]uid: 108015 topic_id: 19198 reply_id: 74470[/import]