Hello again,
Here is another question. I'm working on a simple side scroller. A vehicle moving down a road. I have a vehicle which basically sits in one place.
I also have 2 identical road sprites, each road sprite is the same width as the scene. Road1 starts at (0,199). Road2 starts at (1024,199)
When user clicks right arrow, road1 and road2 moveTo(-1024,199, speed). When the user releases the button, movement stops.
Currently it works fine and the road scrolls until it reaches it's moveTo() destination.
What I want is to reposition the road sprite to (1024, 199) so that can start moving again, making the road appear endless.
The problem is, whenever I check to see if the road has reached x=1024, I get an error saying that "a sprite has invalid coordinates".
Here is the code on my button "onMousedown"
var rd1 = wade.getSceneObject('road1');
var rd2 = wade.getSceneObject('road2');
var car = wade.getSceneObject('plyrVehicle');
var y1 = rd1.getPosition().y;
var y2 = rd2.getPosition().y;
var tree_y = trees.getPosition().y;
var dx = 1;
var curSpeed = car.curSpeed;
while (car.curSpeed < car.maxSpeed) {
car.curSpeed = car.curSpeed + dx;
rd1.moveTo(-1024,y1,car.curSpeed);
rd2.moveTo(-1024,y2,car.curSpeed);
}
I tried adding an IF() within the while loop but I got the error. I tried adding the code to the moveComplete event but obviously that doesn't work because it fires when I release the button, plus I still get the error.
I also tried to substitute moveTo(x,y,s) by simply incrementing the x position of the road while the button is down. Again, the same error.
I believe I am missing the concept behind side scrolling with endless backgrounds. Any suggestions will be greatly appreciated.
Thank you.