Hi,
I'm done trying to solve this on my own... That's 2 sleepless nights now...I need help, guys.
I'm trying to make a sky sprite move sideways, right to left. The idea was to have two screen-sized objects- one starting its loop at x=0, and one just before, at x=800. When the first one reaches x== -800, it's supposed to move directly to x == 800 and then continue moving left. And the same with sky object 2. Of course, the sprite is designed the way that it seamlessly blends into another one. But I end up with this empty gap between them after just the first loop....
Here's the sprite I'm using:
(http://i116.photobucket.com/albums/o27/kurwakurwakurwa/skyscreen.jpg)
I started off with this code (oS1 = sky sprite 1m oS2 = sprite 2) :
function room_AfterFadeIn()
{
oS1.Move(-800, 536, 3, eNoBlock, eAnywhere);
oS2.Move(-800, 536, 3, eNoBlock, eAnywhere);
}
function room_RepExec()
{
if (oS1.X == -800){
oS1.X=800;
oS1.Move(-800, 536, 3, eNoBlock, eAnywhere);
}
if (oS2.X == -800){
oS2.X=800;
oS2.Move(-800, 536, 3, eNoBlock, eAnywhere);
}
}
Please, have you any idea what I'm doing wrong? Is moving objects directly to the other side of the screen causing some sort of delay that creates the gap? But if so, the gap should be growing with each loop, and it isn't.... Perhaps you've got a better idea how to do it?
function room_Load()
{
oS1.X=0;
oS2.X=800;
}
function room_RepExec()
{
oS1.X-=5;
oS2.X-=5;
if (oS1.X<=-800) oS1.X=oS2.X+800;
if (oS2.X<=-800) oS2.X=oS1.X+800;
}
Something like this should work, I believe.
try this.
in rep ex
function repeatedly_execute_always(){
if (oS1.X <= -800) oS1.X = (800 + (oS1.X + 800))
if (oS2.X <= -800) oS2.X = (800 + (oS2.X + 800))
oS1.X -= 3;
oS2.X -= 3;
}
untested though
Edit: RT's solution will work but only because the speed number he used (5 in this case) is a factor of 800.
If it were an odd number like 3 then when it got to -801 (which is the first multiple of 3 greater than 800) then the would snap back to 800 when really it should snap to 799 to keep the flow.
Ryan Timothy: I still get that bloody gap between sprites....
Calin: Damn it.... It works.... Thanks!
Oh right on. I was editing my post while you guys were responding. Har har. Anyway, no idea if it would still work. But at least Calin's works.
Gotta go! Pig roast time.
Sorry for getting back to this thread... but I have a question related directly to it. It's very silly but... how do you make these objects move in the opposite direction(to the right)?
- The only reason I'm asking this is that I really can't understand this piece of code. I'd actually really appreciate if someone could break it down for me and explain *WHY*?.... There are things in it I can't wrap my head around.... and yet it's so gloriously simple!
Well I'll try to explain it - not understanding what was going on in a script has been a bg problem for me too when i started and still is
just look at the annotations
function repeatedly_execute_always(){ //means whats inside here is run at every game loop 40 times a second. alwasy means even during a blocking function
if (oS1.X <= -800) oS1.X = (800 + (oS1.X + 800)) //if your objects position is less than -800 (which means its completely off the screen to the left) move it to 1600 px from its present position (which would result in its x coordinate becoming 800 which is barely off the screen to the right
if (oS2.X <= -800) oS2.X = (800 + (oS2.X + 800)) //does the same thing with object oS2
oS1.X -= 3; //moves the object to the right by 3 pixels /which results in a speed of 120px per second as this is run 40 times a second
oS2.X -= 3;//same for other object
}
Easy isnt it? Now to move the objects to the right ...
function repeatedly_execute_always(){
if (oS1.X >= 800) oS1.X = (-800 + (oS1.X - 800))
if (oS2.X >= 800) oS2.X = (-800 + (oS2.X - 800))
oS1.X += 3;
oS2.X += 3;
}
untested thogh
It works!
And thank you for taking your time explaining. Much appreciated:)