# Math Help: lerp to compensate for parallax

Get help using Construct 2

### » Fri May 01, 2015 12:16 am

my work around is to make the tiled background 40,000x40,000 and somehow push the player back when they get near the edge -- otherwise it will look really bad if the parallax just ends...
B
101
S
34
G
16
Posts: 1,212
Reputation: 17,016

### » Fri May 01, 2015 12:49 am

okay I think I figured out the problem. compensating with lerp gives a number that is not divisible by 512... so I have to bring it to the nearest multiple of 512...
B
101
S
34
G
16
Posts: 1,212
Reputation: 17,016

### » Fri May 01, 2015 1:26 am

You use the layer2canvas expression first, the parameters are fairly straight forward, it uses x and y because it also takes into account rotation as well. After that you use the canvas2layer expression to convert the coordinates to another layer.
the other expression wasn't tested which could explain it not working.

You could try newts sugestion and just move the background by giving it the bullet behavior and setting its angle of motion to be opposite to the players angle of motion. You then would set its speed to 0.25*player.speed to get the same visual effect a paralex, except on the same layer without the need for coordinate calculations.
B
95
S
33
G
128
Posts: 5,491
Reputation: 81,570

### » Fri May 01, 2015 2:12 am

R0J0hound wrote:You could try newts sugestion and just move the background by giving it the bullet behavior and setting its angle of motion to be opposite to the players angle of motion. You then would set its speed to 0.25*player.speed to get the same visual effect a paralex, except on the same layer without the need for coordinate calculations.

I'm not sure how that would work on an unbound layout. The player also can move 360 degrees. Eventually the player will overtake the TB, then what? I would still need to reset the tile over the player, which is what I am doing now.

I have it working except for one small glitch. right at the beginning there's a jump... it's somewhere when the calculation starts..

Here's the latest:
https://www.dropbox.com/s/wc25q2e3m1vph ... .capx?dl=0
B
101
S
34
G
16
Posts: 1,212
Reputation: 17,016

### » Fri May 01, 2015 2:44 am

figured it out..

I was starting the TB at x:940y:540... it needs to start at x:1024y:512 since I'm doing all my math with 512...

WoW... that feels good..

although I'd like to do away with the dummy TB. I could probably replace it with a calculation or variable as I was just using it visually to see what was going on... it looks interesting to have both TB visible..
B
101
S
34
G
16
Posts: 1,212
Reputation: 17,016

### » Fri May 01, 2015 2:47 am

set the scale to 0.25 to see it in action!
B
101
S
34
G
16
Posts: 1,212
Reputation: 17,016

### » Sat May 21, 2016 10:18 am

Hi @jobel

Do you mind sharing the capx one more time? I am facing the same issue on an unbounded side scrolling game I am developing. If it's okay with you, I would like to take a look at how you ended up compensating for the parallax.
In my case I have set my background to parallax at xy(80,100). But unfortunately, after side-scrolling some time a gap would appear. PS.(This doesn't happen when I set parallax back to 100,100)

Many thanks!
B
15
S
7
G
34
Posts: 55
Reputation: 18,478

### » Sat May 21, 2016 8:58 pm

@bloodshot I don't have the capx anymore, but I think I can make one up tomorrow..

basically you want to always make sure you are moving the tile only by 512 (or divisible) that way there can never be a gap or is the movement seen. but if you mean your player is reaching the edge before you move it then you need to increase your tile size.. so instead of 512, you'd need to make it 1024.

The other issue is to make sure the tile's starting position is already at a 512 or divisible x/y.
B
101
S
34
G
16
Posts: 1,212
Reputation: 17,016

### » Sun May 22, 2016 8:00 am

@jobel Thanks man! I would really appreciate it. In the mean time, I created a capx https://goo.gl/wfBqNu demonstrating how I wanted it to be. But as soon as I move the tiledSky object to the Sky Layer, my events become useless. Wondering if you could give a tip on this seeing that you also just move the player in an unbounded layout. Cheers.
B
15
S
7
G
34
Posts: 55
Reputation: 18,478

Previous