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);
}