Page 1 of 1

Question about wrapping actors like in asteroids demo.

PostPosted: Mon Dec 04, 2006 2:28 pm
by ericdg
The asteroids demo contains this code to keep the asteroids and ship in the view.

[code]int w = view.width/2 + width;
int h = view.height/2 + height;
if(x > w) x = -w;
if( y > h) y = -h;
if(x < -w) x = w;
if(y < -h) y = h; [code]

This works fine, but why does it make the actors stay on the 0 axis of the game.

If you have your view in another position other than at 0, the actors will still wrap around 0.

How can I change it to make it wrap around the view regardless of the position of the view?[/code]

PostPosted: Tue Dec 05, 2006 11:59 pm
by makslane
Try this:

Code: Select all
if(x > view.x + w) x = view.x - w;
if( y > view.y + h) y = view.y - h;
if(x < view.x - w) x = view.x + w;
if(y < view.y - h) y = view.y + h;

Re: Question about wrapping actors like in asteroids demo.

PostPosted: Mon Mar 31, 2008 12:20 pm
by DarkParadox
hey mak, theres a problem with that, for some reason it disapears before i goes of screen to the right and takes to long to go on screen from the left...