How do I Get Layers / Z order to play nice?

Get help using Construct 2

Post » Mon May 11, 2015 4:09 pm

Hi there,

I have a project where a character is running along the ground.. but there are layers (think TMNT / Double Dragon side scroller) The player moves between 5 lanes..

The perspective is angled so some obstacles you want to avoid when avoided are either behind or in front of the player.. however when I try various things nothing seems to work..

So far I've tried a number of different things and the overall result is that i'm spawning these obstacles they all seem to want to stay behind or in front of the player..but since the player is constantly moving through the lanes they need to be dynamic..

I tried doing things like "on collision with player" move in front of or behind player object.. I even tried moving to two other layers being ones n front and behind.. but nothing seems to help..

I must not be understanding something fundamental about how these are triggered dynamically.. I have used behaviors like this before in static ways and that's fine, but this is the first time I've had to have things dynamically change.

Thanks!
Caleb
B
56
S
9
G
1
Posts: 938
Reputation: 6,458

Post » Mon May 11, 2015 4:19 pm

so if I understand correctly the player moves between layers..
The objects are on these layers
As far as I know:

If you want the object on the layer to be in front of the player you could use z-order move to top and behind, z-order move to bottom
Probably once the player is send to the layer, the player will be on the top, so you might need to sent the player to the back if needed.
On created - a sprite will allways be created on the top, so it should be sent to bottom if you want it to be behind the player
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon May 11, 2015 4:32 pm

yea sorry that is correct.. imagine there are 5 lanes.. 1 is the highest and 5 is the lowest.. if you were on lane 3.. and the enemy was on lane 4.. you should appear behind it.. if you were on lane 5 you would appear in front of it.

It seems like in general it's one or the other with my current approach.. either they are all in front or all behind.. and to your z order suggestion that's how I was trying to do it.. at least fundamentally, i'm obviously doing something wrong in my attempt.

the issue for me is that an enemy is spawned off the screen to the right and enters the scene.. the player could move since the moment the enemy is spawned so it first appears correct possibly.. but if the player were to change his position any moment after that object is placed on the screen its no longer right..

So I'm trying to get them to behave dynamically and for some reason something like this isn't working:

on collision with player + not on the same lane as enemy, move enemy behind player (z order).. or even more extreme:

on collision with player + not on the same lane as enemy, move enemy to other layer...

As it is the system is a 5 number ID system that indicates which lane the player is.. if player is on lane 3 when touching an object with a Lane 3 ID then it's a hit / game over condition.. then ideally if the number of enemy is greater or less than the player ID it would be smart enough to snap the object to the appropriate z order or layer... though i'd rather not use layers for performance reasons..
B
56
S
9
G
1
Posts: 938
Reputation: 6,458

Post » Mon May 11, 2015 4:39 pm

It is actually pretty simple..

On creation of the object - give it an instance variable from 1 to 5 to decide on which lane it is

Give the player an instance variable to decide on which lane He is..

For each object
-- system compare player.lane<object.lane
> object send to top of layer
-- else
-- object send to bottom of layer

player on collision with object
system compare player.lane=object.lane
> player die horribly

or if you want to only set it on collision

player on collision with object
---system compare player.lane=object.lane
> player die horribly
--- else
---system compare player.lane<object.lane
> object send to top of layer
--- else
> object send to bottom of layer
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon May 11, 2015 4:53 pm

ok I'll try that. i am doing the instance variable already.. the player however has a global variable.. could be made an instance variable but since there was just one player i went with global.. I was already kinda doing this but not exactly so I'll see how your approach goes! :)
B
56
S
9
G
1
Posts: 938
Reputation: 6,458

Post » Mon May 11, 2015 5:09 pm

so yea as far as I can tell i'm pretty much doing it like you said unless i'm overlooking something:

https://www.dropbox.com/s/jbade64tam4bo ... 2.PNG?dl=0

https://www.dropbox.com/s/w365r2nem5fzd ... e.PNG?dl=0


I feel like it's effecting all of them universally and something is preventing each of them from reacting correctly because of this larger inherited behavior.

The only difference I can see is that i'm using a global variable instead of a local, but that wouldn't seem to matter right? I mean the var is still associated with the player object exclusively..

Thanks!
Caleb
Last edited by part12studios on Mon May 11, 2015 5:33 pm, edited 1 time in total.
B
56
S
9
G
1
Posts: 938
Reputation: 6,458

Post » Mon May 11, 2015 5:24 pm

Number one rule in creating events:
Events work by filtering specific instances that meet some conditions. The actions then run for those instances only.
https://www.scirra.com/manual/75/how-events-work

You are not referencing any objects in your event, so all objects are affected..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon May 11, 2015 5:27 pm

Adding a "for each enemy" top level event would be enough..

Instead of system compare you could also do an enemy compare variable action..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon May 11, 2015 5:33 pm

ah ha! man.. and i've been using c2 for awhile now and never realized this.. that did the trick (for each enemy).. that's awesome.. I'll have to remember that in the future.. i figured that the compare value was basically "Every tick" and any time the player position value changed it would update the comparison with each object.. or something auto-magic like that.. heh

Thanks!
Caleb
B
56
S
9
G
1
Posts: 938
Reputation: 6,458

Post » Mon May 11, 2015 5:39 pm

part12studios wrote: i figured that the compare value was basically "Every tick" and any time the player position value changed it would update the comparison with each object..


I guess this is actually true..

But you are not telling C2 which object you want to affect when the condition is true..
The system compare action just compares the values..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Next

Return to How do I....?

Who is online

Users browsing this forum: Allardje, Rudi55, sublimate and 2 guests