Z-Order Place In Front of Another Object

Discussion and feedback on Construct 2

Post » Sat Jan 05, 2013 7:09 pm

I'm to need this feature!
B
5
S
2
G
5
Posts: 97
Reputation: 2,826

Post » Sun Jan 27, 2013 2:12 pm

This feature would be VERY useful. Very difficult working with just "Move to top" and "Move to bottom". Is there a 3rd party plugin available to do this for now?
B
45
S
19
G
10
Posts: 562
Reputation: 9,543

Post » Wed Jan 30, 2013 8:59 pm

I hate to bump this, but, I'd REALLY benefit off of this feature. Just a simple "Move above/below sprite" action would be a total lifesaver (although I'm guessing it's not the easiest thing to do in terms of coding C2's software? Or maybe it's not being added as soon since it's petty and not many people will use it? Iuno) But yeah I hope something like this gets implemented.
B
45
S
19
G
10
Posts: 562
Reputation: 9,543

Post » Thu Jan 31, 2013 12:34 pm

@Jase00

I managed to get around it fairly easily. I created two sprites one green and one red. I also created a player/npc layer and one object layer above and one object layer below. All my objects by default are below the player. I placed the red sprite over solid parts of objects and the green over areas where the player should be behind the object. The I have two events. The first checks to see if the player is overlapping the green. If it is then move the object to the layer above the player. The second is the opposite. If the player is not over the green then trigger once moving objects to the layer below the player. At game startup I set the opacity of both to invisible and the game works fluidly. Maybe that would help.

Here it is in action so you can see how fluid it is.

http://lockegames.com/relicsofyore/city/
B
68
S
21
G
15
Posts: 701
Reputation: 15,604

Post » Fri Feb 01, 2013 3:37 pm

That's an awesome method, though it wouldn't work with what I need it for.
I have characters that have items of clothing on them that can be changed, and some of the frames of the character involve shifting certain parts of the body/clothes to certain Z Levels (One attack would have the arm go in front of the characters head, and another attack could go behind it) Not to mention that there is multiple characters that will have this, so if one character does an attack then stands in front of another character, all his clothes will overlap the other character incorrectly and whatnot. Making ordered events that put the characters clothing to "Move To Top" every tick to correct their order seems inefficient (That's my current workaround though). :)
B
45
S
19
G
10
Posts: 562
Reputation: 9,543

Post » Fri Feb 01, 2013 8:56 pm

On the topic of Z-order, it can be very difficult in HTML 5 to accurately control Z-order due to the fact that Z-Order is affected by object hierarchy and container context as well. Not that it isn't something that the Scirra Folks can't get around, just saying it may be a bit more difficult than it was in CC.

Even if you set the Z-Order priority for objects, they can be effected by their containers context as well as things like transparency settings... it may seem odd, but there are some seemingly wacky things that can throw off z-order in HTML 5.
B
49
S
11
G
10
Posts: 1,833
Reputation: 14,418

Post » Fri Feb 01, 2013 9:03 pm

@lanceal I was thinking of something similar, but splitting all my objects between the two layers where the base or ground touch portion of each object lives on the lower level and has as solid behavior, then the upper portion of each sprite lives on the upper layer where my player can just walk behind it.

Is there any performance hit for your method of swapping the layers for the sprite? Would it not work just to have all of the objects on the layer above the player, and just set a tile on the lower layer to solid that matches up to the bottom portion of the object? For example have the tree be on the layer above, but on the lower layer have an invisible tile that matches up with the location of teh base of the tree and set it to solid? Then you would not need to do any switching.
B
49
S
11
G
10
Posts: 1,833
Reputation: 14,418

Post » Sat Feb 02, 2013 8:08 pm

@BluePhaze

Splitting the images up into two I'm not sure but I think might cause more of a delay, even by a millionth of a second. Although I'm not sure. My thoughts are two seperate images need to be rendered in the engine before they can be stamped onto the canvas. Where what I'm doing is this:


The red and green are each one image that are placed over each sprite. So it renders once before stamping over each image is what I'm assuming. Red is the collision sprite. So its set to solid versus the actual building. Then its a matter of checking for collision with the green image.


Everyone I've had test it so far has told me the movement is fluid with no to little stuttering.
B
68
S
21
G
15
Posts: 701
Reputation: 15,604

Post » Sat Feb 02, 2013 10:59 pm

Awesome, thanks! I was just wondering, if all the items that the player can go behind are on a layer above the player, then all you need is to make all red sprites solid, and you can get rid of the green ones right? THe player will stop when they hit the red sprite, if they move to where they will be hitting the green they will pass behind the image.

Sorry if I am dragging this out, I am just looking at a way to do it without swapping objects on layers to save a bit or resources.
B
49
S
11
G
10
Posts: 1,833
Reputation: 14,418

Post » Sat Feb 02, 2013 11:32 pm

@BluePhaze

The problem there is with the building above. Placing it always a layer above my player will mean that it will still show below the building, like he dug a hole and started crawling under the building. By placing the building below the player then by default he can walk in front of a building and show up like he is standing in front if it. Then if the player walks into the green the building flips to the layer above so he is then showing behind the building. If that make sense?
B
68
S
21
G
15
Posts: 701
Reputation: 15,604

PreviousNext

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 5 guests