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.

2D All the way! / Sprite movement, jumps back to original position

Author
Message
johnvn
21
Years of Service
User Offline
Joined: 15th Apr 2003
Location: United Kingdom
Posted: 17th Apr 2003 15:23
hi, iam trying to move a sprite left and right, when i use the left and right keys. i have got the code but the sprite always jumps back to the middle of the screen. help !!

gunposition = Screen Width() / 2

playercontroll:

LOAD IMAGE "C:\WINDOWS\Desktop\darkbasic\player1.bmp",1

SPRITE 5,298,457,1

rem if leftkey() = 1 then player = gunposition - gunspeed
rem if rightkey() = 1 then player = gunposition + gunspeed

x=sprite x(5)
y=sprite y(5)

if leftkey() = 1 then x = gunposition - gunspeed

if rightkey() = 1 then x = gunposition + gunspeed

sprite 5,x,y,1

return
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 17th Apr 2003 16:13 Edited at: 17th Apr 2003 16:13
It's because your sprite position is based on 'gunposition' which you never change.

Try something like this instead:

Login to post a reply

Server time is: 2024-04-25 18:09:35
Your offset time is: 2024-04-25 18:09:35