How do I maintain an object position when moving it to another layer?

0 favourites
  • 6 posts
From the Asset Store
This is a code so you can see the same skin on all screens (peers). Each peer gets a skin, in addition to 4 directions t
  • Hello!

    I have an object on a parallax layer, and when I move it to a layer that has no parallax, it (of course) suddenly changes position due to the layers behaving differently.

    Is there a way to get it on to the non-parallax layer that maintains its on-screen position, please?

  • The parallax setting is based on a percentage of the non parallax xy's.

    Do you know how to figure percentages?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I do, but I'm not sure how I'd apply it in this particular problem.

    My best guess so far has been:

    -> inventoryItem: Move to layer "UI"

    -> inventoryItem: Set position to (Self.X - LayerParallaxX("Background"), Self.Y - LayerParallaxY("Background"))

    I'm aware there are no percentages here, just stuck as to how I'd use them!

  • I would use LayerToCanvas X/Y to get the coordinates on the current layer, then CanvasToLayer X/Y to get to the new layer at the equivalent position.

  • Yeah I was just thinking that might be a better way to go.

  • Thanks guys, I hadn't heard of the Canvas To Layer function before. After a bit of digging I've got it working using this code:

    -> inventoryItem: Set position to (CanvasToLayerX("UI", LayerToCanvasX("Characters", inventoryItem.X, inventoryItem.Y), LayerToCanvasY("Characters", inventoryItem.X, inventoryItem.Y)), CanvasToLayerY("UI", LayerToCanvasX("Characters", inventoryItem.X, inventoryItem.Y), LayerToCanvasY("Characters", inventoryItem.X, inventoryItem.Y)))

    -> inventoryItem: Move to layer "UI"

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