Aligning parallax with other layers?

1 favourites
  • 14 posts
From the Asset Store
Set of 10 Parallax Background to make pixel art game.
  • Does anyboby have any ideas for what the maths would be to align 2 objects that are created on layers with different parallax?

    Here is an example project and a screenshot to illustrate the problem:

    capx drive.google.com/file/d/1dDEQJZhRHAB-9DqWdzLSLSFWF8SQxabX/view

    My 2 objects are not aligned when the're the player is in center of the screen!

    I made an old topic here on parallax maths, but I don't know if that helps me here or not: construct.net/en/forum/construct-3/how-do-i-8/parrallax-maths-142131

    Thank you for your help 😍

  • You have to take in account that the background is also scrolling only with half of the speed.

    Try: -> System: Create object back on layer "back" at (fore.X÷2+OriginalViewportWidth÷4, 175)

    for the background object.

  • You can use LayerToCanvasX LayerToCanvasY CanvasToLayerX CanvasToLayerY expressions.

    For example, to convert X/Y coordinates from layer "A" to layer "B":

    newX = CanvasToLayerX("B", LayerToCanvasX("A", x, y), LayerToCanvasY("A", x, y))

    newY = CanvasToLayerY("B", LayerToCanvasX("A", x, y), LayerToCanvasY("A", x, y))

  • Thanks eberyone!

    dop2000 I forgot about that expression! But I can't figure out how to get it to work for me.

    It's not even on the screen any more.

    drive.google.com/file/d/1v9a1p3ylHrEfc0vhmqbMYPPLLK8PG2GF/view

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If you change X coordinate for both objects to something like 150, you'll see that they are aligned at the moment of creation.

    But since you are creating them at x=1250, when character moves in their direction, it takes twice the distance to get to the "back" sprite, because it's on 50% parallax layer.

    If you want these objects to always be aligned, you need to adjust "back" position on every tick. Or simply place it on layer with 100% parallax.

  • dop2000 Thanks for reply.

    I don't want them to always be aligned. In my original post, I tried to explain that I only want the created objects to align perfectly when the player/camera is right on top of them.

    My 2 objects are not aligned when the're the player is in center of the screen

  • In this case I guess the easiest solution is to temporarily set scroll to "fore" object, create "back" object with those expressions, and then set scroll back to the player.

    Edit: just tested and it works.

  • Asmodean that works great! I couldn't figure out why the OriginalViewport was divided by 4 though? I understand that halving it would get to the center of the viewport, but when I tried to use other parallax values (e.g. 30%) I couldn't figure out an equation that would work in that section.

    dop2000 Ah that seems to work, a great simple solution, appreciate the assistance! 💖

  • You can also create "back" at these coordinates:

    X: (1250+OriginalViewportWidth/2)/2

    Y: (350+OriginalViewportHeight/2)/2

  • I can't get that to work for me? At least when the layer is 30% parallax, here is the equation I used:

    X: (fore.x + (OriginalViewportWidth*0.5) ) *0.3

    Y: (fore.Y + (OriginalViewportHeight*0.5) ) *0.3

  • The alignment isn't occuring in the center of the screen with the above equiation

  • Try this:

    X: OriginalViewportWidth/2+(1250-OriginalViewportWidth/2)*0.3

  • for 30% in X it would be:

    -> System: Create object back on layer "back" at (fore.X×(0.3)+OriginalViewportWidth×(0.35), 175)

    fore.x*(parallax in x) + OriginalViewportWidth*(0.5-(parallax in x)/2)

    fore.X×( 0.3 )+ OriginalViewportWidth×(0.5-0.3/2)

  • thanks!

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