Display object order

Hi,

I have a problem displaying objects on the screen in the right order that I’m not sure is solvable. I have three objects x y and z.

I want x above z
y above x
and z above y

is this solvable? is there something I can use to get this correct display order?

Thanks,
Chris

[import]uid: 126017 topic_id: 28140 reply_id: 328140[/import]

So getting the “order” of the object as you want you would declare them as follow:
PS: It`s ONLY a “hard” example!

[lua]local X = display.newImage (“x.png”); – X is below Y and Z
local Y = display.newImage (“y.png”); – Y is below Z and above X
local Z = display.newImage (“z.png”); – Z is above X and Y[/lua]

So, to have the exactly order you want you would use the [lua]object:toFront( )[/lua] API - “as soon as you need it” - that you can follow some examples here --> http://docs.coronalabs.com/api/type/DisplayObject/toFront.html

Have a look into the Coronas API link above that for sure youll get to “understand” how to do it about the right order (regarding your needs).
I hope that helps.
Cheers,
Rodrigo.
@RSCdev [import]uid: 89165 topic_id: 28140 reply_id: 113697[/import]

In your comments above it says z is above x but in fact I want z bellow x. Can this be fixed with the API you mentioned above?

Thanks,
Chris [import]uid: 126017 topic_id: 28140 reply_id: 113699[/import]

@Chris, answering your question above, I would say yes! You just have to use the [lua]object:toFront[/lua] API to give the order you want to any object.

For example, if Z is above X , when you use the API I said above you would get exactly what you want as: X above Z or the same as Z below X.

Have a try and report here what you get or what you are getting. .)
PS: But if you only need the Z"below" the X during all the time of your app, SO you would need only to declare it right before declare the X on your code declaration! Else you need it sometimes BELOW or sometimes ABOVE, so you could really use the Corona`s API I have said on the post above.
Cheers,
Rodrigo. [import]uid: 89165 topic_id: 28140 reply_id: 113700[/import]

Hey I’ve looked at the object:toFront api and still don’t understand how it would help me with my problem. I think maybe my explanations are a little faulty. Maybe this example will help?

I have three objects: Nightshade, Actor, Star

I want the Actor to always be behind the Nightshade
I want the Star to always be behind the Actor
and I want the Star to always be above the NightShade

Does the toFront api still work for this? I can’t see how it would help?
[import]uid: 126017 topic_id: 28140 reply_id: 113742[/import]

You want Actor behind Nightshade, Star behind Actor AND Star in front of Nightshade? That wont work. How can the star be behind the actor but still in front of something in front of it? That means the star is meant to be somehow behind and in front of the actor from what I can understand.

Do you have an image mockup of what you hope to achieve? [import]uid: 52491 topic_id: 28140 reply_id: 113779[/import]

@Peach,

I thank you so much for trying to shed a light here my friend.
Cheers,
Rodrigo. [import]uid: 89165 topic_id: 28140 reply_id: 113795[/import]

I haven’t read the entire thread thoroughly so sorry in advance. But maybe turn them all into physical bodies and when theirs collision between the Star and the Actor, make the Actor on top or just hide the star till it’s over. [import]uid: 77199 topic_id: 28140 reply_id: 113801[/import]

@Peach,

I don’t have a mock up but basically you have mentioned the issue I am trying to solve. I am attempting to make night and day time. However at night I want things to glow, and I believe that in order for them to appear as if they are glowing, they must be on top of the night shade. However the actor must be above everything but the night shade, so as to make the actor appear darker as if it were night. I might end up using a different animations for the actor in order to simulate the night time that way the actor can always be above everything. It would however be a lot nicer if I didn’t have to worry about making a day and night animation for the actor. Do you have any suggestions for this problem. Also thank you very much to everyone for helping me out.

@hatethinkingofnames

nice name:). I have thought about doing what you suggest but I would prefer to not make a bunch of physics bodies. Especially when some of the objects I wish to have glowing are part of a big png and I would have to do some very tedious measurements in order to get them to all have individual physic bodies. But thank you for the idea.
[import]uid: 126017 topic_id: 28140 reply_id: 113804[/import]

Well this is an interesting problem, got rid of my morning boredom.

I’m guessing your actor will be some kinda character so he will be having physics to begin with? How are you doing the glowing part? What’s exactly in this big png? Just all the stars? Or all shorts of object and stuff? How are you adding the glow? Do you separately add a glow outline as another image/animation?

You can create a polygonShape just for collision purposes that won’t even be seen. Depending on how your game is exactly you can even just use a circle for collision, that will save you a shitload of time from having to do collision for different size stars, this way you just change the radius and done. [import]uid: 77199 topic_id: 28140 reply_id: 113808[/import]

Yep the actor does have physics.

The glowing part is simple. It is art I have made that will be a sprite sheet and will be pulsating and appear to be glowing. However if a night shade was to come over the art it would take away from the affect or appearance of glowing. The big png is all the fruit that corresponds to a a tree that has glowing fruit. (think avatar ha :slight_smile: ). The glowing object is simply a sprite animate that will appear to be glowing/pulsating.

I know I can create polygon shapes as well however I think that this will be to faulty as I am scaling in the game and the physics bodies don’t scale so I will have to remove and add, and on top of that have to do way to much stuff in order for that to work.

I think my best bet so far is having some sort of individual night shade for my actor so he appears under the nightshade.

I would prefer to have some sort of fix however as I am going to be creating glowing images on certain collisions and at the collision point it would be nice if the glowing sprite sheet was on top of one thing but not on top of another. However the top image i wish to have on top of the glowing image is behind the other image that I wish to have the glowing image behind. So basically the same problem as above. I’m just not sure it is possible, but I was kinda hoping someone had found a good fix.

Chris [import]uid: 126017 topic_id: 28140 reply_id: 113829[/import]

It seems from what you have said that indeed you will want a 2nd animation for your character during the night phase - simply because you cannot layer in the way originally described, for reasons outlined in my last post. A behind B behind C cannot have A also in front of C while remaining behind B.

Sorry - but your 2nd animation fix does sound like the most reasonable solution here. [import]uid: 52491 topic_id: 28140 reply_id: 113883[/import]