How do I make a Prince of Persia-like scrolling

0 favourites
  • 5 posts
From the Asset Store
All popular touch mechanics - scrolling, zooming, swiping
  • How do I make a Prince of Persia-like scrolling? I mean when the background is fixed, and then scrolled left or right when the player approaches left/right margin of the window.

  • Use floor(x / y) * y to round (down) to a number.

    E.g. scroll to floor(player.X / 128) * 128 will scroll every 128 pixels.

    You can also set up areas manually to set scroll position. On collision scroll to the object.

  • Thank you (and sorry for late response) .

    Can you please describe how the construction "scroll to floor(player.X / 128) * 128" is working? I got some results but not what I wanted. Probably because I did not get, how does it work.

    If I have screen width 1024, does it means I have to use (player.X/1024)*1024?

  • ankas Yes. floor(x) rounds down to the nearest whole number.

    floor(1.7) = 1

    floor(1.7 * 10) = 17

    floor(70 / 64) = 1

    floor(70 / 64) * 64 = 64

    floor(137 / 64) * 64 = 128

    Divide first so that it is rounding based on that number, then round. Then multiply to get back to the original scale.

    You can also use mod(x, y) which returns the remainder of a division.

    scrollx = player.x - mod(player.X, 64)

    This will round down to multiples of 64. The mod() function returns what's left after dividing (the remainder), which is what we want to get rid of.

    If you are using rooms or what have you, and need to have the camera be in a set position instead of at intervals, you can place objects which on collision move the camera to its center.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks a lot! It's working!

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