Question about wrapping actors like in asteroids demo.

Non-platform specific questions.

Question about wrapping actors like in asteroids demo.

Postby ericdg » Mon Dec 04, 2006 2:28 pm

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]
ericdg
 
Posts: 53
Joined: Tue Nov 29, 2005 1:18 pm
Score: 1 Give a positive score

Postby makslane » Tue Dec 05, 2006 11:59 pm

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;
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Re: Question about wrapping actors like in asteroids demo.

Postby DarkParadox » Mon Mar 31, 2008 12:20 pm

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...
User avatar
DarkParadox
 
Posts: 457
Joined: Mon Jan 08, 2007 11:32 pm
Location: USA, Florida.
Score: 84 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron