[Solved]How do I Move an Object in Layer Depends on Y axis?

Get help using Construct 2

Post » Sat Dec 24, 2016 3:11 pm

I have a sprite which have 3 frame colored red,blue and green.

Image

Green one is top of the layer
Red one is the middle of the layer
Blue one is bottom of the layer

Image

I want to do this; pick sprite instance which Y axis > the other instances y axis,move that instance which is picked in front of the other instances on layer.

Edit : I solved the problem using 'For each ordered' loop.

Sort object instances by Y co-ordinate:

+ For each Sprite order by Sprite.Y ascending
-> Sprite: send to front
B
23
S
11
G
1
Posts: 127
Reputation: 2,737

Post » Sun Dec 25, 2016 9:43 am

That works. But it is a bit 'the old way'. It can be done faster today, with loops (in the background) optimised by C2 code.

First give the Sprite an instance variable, lets say 'Yposition'

Top-level event
or system > condition > Trigger Once While true (when you want to do it only once)
or system > condition > Every Tick (when you want to do it continues)
_______Action > Sprite > Set value > 'Yposition' = Self.Y (this loops (optimised) trough the sprites and sets the instance variable for each)
_______Action > System > Sort Z order > object = Sprite ... Instance variable = 'Yposition' (this will set the Z order for (another optimised loop) each sprite based on Y, nicely packing the indexes)
B
33
S
18
G
28
Posts: 2,455
Reputation: 20,874

Post » Sun Dec 25, 2016 12:53 pm

@99Instances2Go Oh,thank you!
B
23
S
11
G
1
Posts: 127
Reputation: 2,737


Return to How do I....?

Who is online

Users browsing this forum: ketramtu18 and 11 guests