|
|
Another loop problem
#329405
06/19/10 16:06
06/19/10 16:06
|
Joined: Jun 2007
Posts: 15 Norway
Gastara
OP
Newbie
|
OP
Newbie
Joined: Jun 2007
Posts: 15
Norway
|
I’m still playing/testing different loops for sprite on 2D map. This one is for me more complex. I understand the solution on this thread Loop problem and have tried to use it in this example, but with no result. In the code below the sprite moves right – down – left – up, and that works fine. The idea is to make an endless loop out of this. For now, it just stops at the start point. Is it an easy solution for this, or should I try to write the code in another way?
// How to make a loop out of this...
while (1)
{
obj_pan.pos_x += speed_x;
if(obj_pan.pos_x >= 500)
{ speed_x = -speed_x;
while (1)
{
obj_pan.pos_y += speed_y;
if(obj_pan.pos_y >= 500)
{ speed_y = -speed_y;
while (1)
{
obj_pan.pos_x += speed_x;
if(obj_pan.pos_x <= 300)
{ speed_x = -speed_x;
while (1)
{
obj_pan.pos_y += speed_y;
if(obj_pan.pos_y <= 300)
{ obj_pan.pos_y = 300;}
wait(1);
}
}
wait(1);
}
}
wait(1);
}
}
wait(1);
}
|
|
|
Re: Another loop problem
[Re: Rei_Ayanami]
#329409
06/19/10 16:34
06/19/10 16:34
|
Joined: Jun 2007
Posts: 15 Norway
Gastara
OP
Newbie
|
OP
Newbie
Joined: Jun 2007
Posts: 15
Norway
|
Thanks for helping Rei_Ayanami, but now it goes right - up in second loop. It look like this now, right - down - left - up - right - up and out of the screen. Thanks for helping anyway.
Last edited by Gastara; 06/19/10 16:39.
|
|
|
|