Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (TipmyPip), 18,619 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Another loop problem #329405
06/19/10 16:06
06/19/10 16:06
Joined: Jun 2007
Posts: 15
Norway
G
Gastara Offline OP
Newbie
Gastara  Offline OP
Newbie
G

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?

Code:
// 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: Gastara] #329407
06/19/10 16:19
06/19/10 16:19
Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
Rei_Ayanami Offline
Expert
Rei_Ayanami  Offline
Expert

Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
Please:
Code:
while(1)
{
	while (obj_pan.pos_x <= 500)
	{
		obj_pan.pos_x += speed_x;
		wait(1);
	}
	obj_pan.pos_x = 500;
	speed_x = -speed_x;
	while(obj_pan.pos_y <= 500)
	{
		obj_pan.pos_y += speed_y;
		waít(1);
	}
	obj_pan.pos_y = 500;
	speed_y = -speed_y;
	while(obj_pan.pos_x >= 300)
	{
		obj_pan.pos_x += speed_y;
		wait(1);
	}
	obj_pan.pos_x = 300;
	speed_x = -speed_x;
	while(obj_pan.pos_y >= 300)
	{
		obj_pan.pos_y += speed_y;
		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
G
Gastara Offline OP
Newbie
Gastara  Offline OP
Newbie
G

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.
Re: Another loop problem [Re: Gastara] #329411
06/19/10 17:26
06/19/10 17:26
Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
Rei_Ayanami Offline
Expert
Rei_Ayanami  Offline
Expert

Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
sry, i forgot a speed_y = -speed_y;

while(1)
{
while (obj_pan.pos_x <= 500)
{
obj_pan.pos_x += speed_x;
wait(1);
}
obj_pan.pos_x = 500;
speed_x = -speed_x;
while(obj_pan.pos_y <= 500)
{
obj_pan.pos_y += speed_y;
waít(1);
}
obj_pan.pos_y = 500;
speed_y = -speed_y;
while(obj_pan.pos_x >= 300)
{
obj_pan.pos_x += speed_y;
wait(1);
}
obj_pan.pos_x = 300;
speed_x = -speed_x;
while(obj_pan.pos_y >= 300)
{
obj_pan.pos_y += speed_y;
wait(1);
}
obj_pan.pos_y = 300;
speed_y = -speed_y;
wait(1);
}

Re: Another loop problem [Re: Rei_Ayanami] #329414
06/19/10 17:35
06/19/10 17:35
Joined: Jun 2007
Posts: 15
Norway
G
Gastara Offline OP
Newbie
Gastara  Offline OP
Newbie
G

Joined: Jun 2007
Posts: 15
Norway
Very very nice, it works fine now. I shall study it and learn from it. Thank u very much.

Re: Another loop problem [Re: Gastara] #329415
06/19/10 17:39
06/19/10 17:39
Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
Rei_Ayanami Offline
Expert
Rei_Ayanami  Offline
Expert

Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
no problem


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1