Trouble Finding Layer Position with Parallax

0 favourites
  • 5 posts
From the Asset Store
Set of 10 Parallax Background to make pixel art game.
  • Hi!

    I am trying to have my game create a tiled background on a Layer with a parallax of 90, 90. I am having trouble placing it at the right position, as I want it to be aligned with objects on layers with normal parallax, but its always way too much to the left/right/up/down etc.

    (320, 288 is the window size, since the array position given is in the top-left corner I added those in as a way of centering it. Doesn't work.)

    I've tried using the LayerToCanvasX and then CanvasToLayer X solution I've seen people use, but I am still having issues. I believe it might have something to do with the position it is currently scrolled to at the time of spawning the object? I'm a bit out of my depth here and I;m not really sure what to do next?

    For context my game randomly generates the map at the beginning of the run, and I want to place a background in a transparent spot (on the layer with 90,90 parallax) behind the normal background (on the layer with normal parallax). That way the background on the bottom scrolls differently than the background on the layer above, giving the area a bit of depth. I just can't figure out how to calculate the proper position taking parallax into account!

    Can someone help me with this? Thanks in advance, I'm pretty stumped.

  • Bump.

  • you are using LayerToCanvas / CanvasToLayer correctly as far as I can tell.

    so the problem is either with the origin of the objects or something not being where you think it is...

    you will have to make a small sample file with the two layers and a couple of the objects so we can see what it going on.

  • you are using LayerToCanvas / CanvasToLayer correctly as far as I can tell.

    so the problem is either with the origin of the objects or something not being where you think it is...

    you will have to make a small sample file with the two layers and a couple of the objects so we can see what it going on.

    With further testing, I think what is probably happening is that the game is placing the tiled backgrounds correctly, but by the time the Player has reached that part of the map the layer has already been scrolling differently with parallax and makes the objects appear as misaligned... not sure how to account for that.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I think it may be one of those things that construct doesn't update the values of until things are drawn. So the result is the calculation gives a position one frame behind.

    I haven't used those equations but I had the same issue when trying to get the screen left right after setting the scroll position. My solution was to calculate it manually.

    Off the top of my head this should give you the x,y position of the center of the screen on the 90,90 parallax layer. I haven't tested it though.

    x = scrollx*0.90

    y = scrolly*0.90

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