Jump to content
  • Advertisement
Sign in to follow this  
bugboy

Parallax Problem

This topic is 5010 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In my game I want to be able to easily create different parallax layers by setting their scrolling ratio and having a function calculate how big their tile array needs to be in order to meet with the main tile array. Currently my function looks like this, it works for .5, but when the ratio is changed to .25 there is a small gap. void ParaLayer::setratio(float r,int NUX,int NUY, int sw, int sh) { ratio=r; NUMX=(NUX*ratio)+(((sw/2)/32))+1; NUMY=(NUY*ratio)+(((sh/2)/32))+1; tiledata.resize(NUMX); for(int i = 0; i < NUMX; i++){ tiledata.resize(NUMY);} } NUX & NUY are the width and height of the main tile array the one that the player interacts with. sw & sh are the screens width and height NUMX & NUMY are the layers tile array width and height You use the function like this: layers[1].setratio(.25,NUMX,NUMY,Engine.SCREENWIDTH,Engine.SCREENHEIGHT); Makes this layer scroll 1/4 as fast as the main tiles layers[0].setratio(.5,NUMX,NUMY,Engine.SCREENWIDTH,Engine.SCREENHEIGHT); Makes this layer scroll 1/2 as fast as the main tiles This is probably hard to understand but hopefully someone will be able to help me. Thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
Are NUX and NUY evenly divisable by 2 but not 4? That would cause a rounding error when you convert to an int.

What is the +(((sw/2)/32)) term there for?

Share this post


Link to post
Share on other sites
You are losing accuracy as you are using ints and so if the division is not a whole number, you are getting a rounding error which explains your gap.

A simple solution would be to round up always so you have an extra tile of columns eliminating that gap.

A even cleaner solution would be to not scale up the background parallax layers at all but to implement a scrolling system which when the end tile column is reached, it wraps around to the first tile column. This will then create infinite background parallax layers.

- Oscar [smile]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!