How do I get the position of a object in a parallax 100 layer for another object in parallax 0?

0 favourites
  • 5 posts
From the Asset Store
This sound pack comes with 100 high quality, ready-to-use sound effects for all kinds of games.
  • I want to set the position of an object to another object. But they are in different layers with different parallax.

    What I want:

    Target position object (race_flag): ("river") layer parallax 100%

    Object to be moved (ruler): ("ruler") layer parallax 0%.

    I tried CanvasToLayerY but it didn't work. This is how I used it:

    (CanvasToLayerY("ruler", LayerToCanvasX("river",race_flag.X,race_flag.Y), LayerToCanvasY("river",race_flag.X,race_flag.Y))

    I tried interchanging layers and values in the code but it still didn't work. Is there any other way to achieve this?

  • You want to find the difference between the 2 layers and adjust the location by that much.

    I made a video that can walk you through it if you're having any difficulties:

    https://youtu.be/inpTVBWI9v4

  • (CanvasToLayerY("ruler", LayerToCanvasX("river",race_flag.X,race_flag.Y), LayerToCanvasY("river",race_flag.X,race_flag.Y))

    This expression is correct. It will convert flag Y-coordinate from layer "river" to layer "ruler". Make sure that the objects are on the right layers.

    If it still doesn't work, please post a screenshot of your events.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hi, thanks for the solutions. The code I was using was indeed right. It was not working as I was using it in start of layout. It worked after I moved it and all associated events to the update loop. It took me hours to figure it out.

    Thanks a ton winstreak for the video. This was a confusing topic. Your video really helped me understand it a lot better.

  • Sure thing Shanjei, glad I could help.

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