# How do I make a Prince of Persia-like scrolling

Get help using Construct 2

### » Mon Jun 26, 2017 8:10 pm

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.
B
16
S
6
G
1
Posts: 23
Reputation: 1,707

### » Tue Jun 27, 2017 1:12 am

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.

Take a look at my itch.io games
B
45
S
14
G
3
Posts: 167
Reputation: 5,204

### » Sat Jul 08, 2017 3:14 am

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?
B
16
S
6
G
1
Posts: 23
Reputation: 1,707

### » Sun Jul 09, 2017 2:57 am

@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.

Take a look at my itch.io games
B
45
S
14
G
3
Posts: 167
Reputation: 5,204

### » Mon Jul 10, 2017 7:56 pm

Thanks a lot! It's working!
B
16
S
6
G
1
Posts: 23
Reputation: 1,707