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 / Physics Question (Sprite Velocity)

Author
Message
Bryan Green
7
Years of Service
User Offline
Joined: 16th May 2016
Location:
Posted: 27th May 2016 05:01
Hi, all-- so I thought what I had was a good solution to keep a physics-based spaceship sprite that is moved left and right on the screen (a la Space Invaders, Galaga) from going off the edges of the screen; when the ship hits the left or right edge, I set the X velocity to 0. However, when I press my left/right keys to then move back in the opposite direction by changing the X velocity back to a positive or negative number, the ship doesn't move.

Does something have to happen before changing the velocity from 0 to another value before the sprite will start moving again?

Thanks!
Bryan
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 28th May 2016 08:29
Setting the velocity should get it moving... unless your "is it touching the edge" check is still true in which case you'd be setting the velocity back to zero again. Can you post a small example that highlights the problem?
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 29th May 2016 12:06
Using physics for something so simple is major overkill.
I would turn off physics and simply place sprite directly. Increase it's position if you press right and decrease it if you press left.
No physics, no velocity = simples
AGK V2 user - Tier 1 (mostly)

Login to post a reply

Server time is: 2024-04-26 12:16:26
Your offset time is: 2024-04-26 12:16:26