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

0 favourites
  • 3 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • I have a sprite which have 3 frame colored red,blue and green.

    Green one is top of the layer

    Red one is the middle of the layer

    Blue one is bottom of the layer

    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

  • 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)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 99Instances2Go Oh,thank you!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)