Jump to content

Parallax: Predict length of level


Davaaron
 Share

Recommended Posts

Hi,

I implemented a platform game and a parallax effect with different background levels which are shifted to the left in the update function. The value they are shifted by is calculated based on the current speed of the main object moving.

I'm using box2d (I'm not happy though as I haven't found real helpful documentation besides the few examples). The problem is, that I get a black background as there is no background anymore when I'm about to reach the end of the level.

My approach to solve this is to compute the time T taken to finish the level when you drive with an average speed (which is the half of the maximal speed). As I know the factor the backgrounds are shifted by (0.2 * currentSpeed), I could take the time T and apply it to a kinematic formula to receive the distance that the backgrounds would have travelled under the mentioned circumstances. Physics says it's simply:

s = v * t => t = s/v

Let's assume the level has 10.000 pixels and the average speed is 50. The result is t = 200 = 10.000 / (0.5 *  50). The truth is I need 35 seconds for that level without being even blocked or respawned or anything else.

I do it the following way:

	var lvlWidthPx = this.game.state.getCurrentState().camera.bounds.width;
	var avgSpeed = this.speed / 2;
	var timeNeed = lvlWidthPx / avgSpeed;

Do you guys have a good idea how to solve that? Maybe there is even a better for do realize the parallax (as I'm shifting each single background element whether it's in sight or not)?

How would you calculate the minimum level length then?

 

I appreciate your answers!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...