Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Wrap Sprite like Asteroids (no physics)

Author
Message
crazy_asian
9
Years of Service
User Offline
Joined: 13th Jul 2015
Location:
Posted: 13th Jul 2015 19:11
Hi All,

I just started using AppGameKit 2 over the weekend so be gentle

I create a top down space shooter with no physics. Everything is moved using SetSpriteX and SetSpriteY in the main loop.

I was wondering how to have sprites wrap from right to left/left to right on the screen? I don't need to wrap from top to bottom or bottom to top. I saw some wrapping functions in the help, but those didn't look like what I needed.

Also, I saw a similar post that talked about sprite impulse and angular velocity, but I didn't think that applied in this instance?

Any help would be greatly appreciated.
=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 13th Jul 2015 21:43
Simply check to see if the sprite has gone off screen

GetSpriteX(spriteID) returns the X position of the sprite.

Check to see if this value is less than 0 or greater than the Width of the screensize you are using. (Or 100 if you are using the percentage system)

If it is, then simply reposition the sprite where you want it to be

JLMoondog
Moderator
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Paradox
Posted: 13th Jul 2015 23:45
Here's an easy to use function that you can plug right in and it'll work with any sprite.



It's easy to use.

Sprite - the sprite you want to wrap around the screen
Physics - 1 = sprite has physics / 2 = sprite doesn't have physics
vx - Sprite's velocity x ( only used if physics = 1 )
vy - Sprite's velocity y ( only used if physics = 1 )

crazy_asian
9
Years of Service
User Offline
Joined: 13th Jul 2015
Location:
Posted: 14th Jul 2015 18:54
Ah, thanks for your help all!

I'll give this a go tonight.

Login to post a reply

Server time is: 2024-11-16 18:19:43
Your offset time is: 2024-11-16 18:19:43