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.

Newcomers DBPro Corner / Need help with arrow key movement in dark basic

Author
Message
Zombie dwarf
18
Years of Service
User Offline
Joined: 15th Mar 2006
Location:
Posted: 29th Mar 2006 19:04
I have this code thats supposed to move an object around the screen with the arrow keys, it doesn't work though, can someone please show me what I've done wrong?

=================
HIDE MOUSE
CLS
SYNC RATE ON
SYNC RATE 30

POSITION CAMERA 0,0,0

SET AMBIENT LIGHT 15

POINT CAMERA 0,0,0

LOAD BITMAP "character.bmp", 1

GET IMAGE 1,0,0,27,27

SPRITE 1,300,210,1

IF LEFTKEY()=1 then speedx#=speedx#-5.0

IF RIGHTKEY()=1 then speedx#=speedx#+5.0

IF UPKEY()=1 then speedy#=speedy#+5.0

IF DOWNKEY()=1 then speedy#=speedy#+5.0

WAIT KEY

END
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 29th Mar 2006 21:10
Looks like someone's been skipping ahead in the tutorials a bit...

You need a loop in there, otherwise all the program will do is check for each keypress once and then await a final keypress to end the program. I dont have much time to explain now but basically;



Im sure someone else will come along and explain why, either way I've gotta run.

- RUC'

Jerok
19
Years of Service
User Offline
Joined: 7th May 2005
Location: Mars. Wait a sec I\'m on MARS. OMG
Posted: 30th Mar 2006 04:11
like ruccus said the waitkey command will wait for a keypress end the command end will obviously end the program so once you press a key(left right up down in your case) the program ends by establishing a loop it tells the program to repeat the code inside the loop therefore allowing your program to continue running
also you are not changing the sprites place on the screen you have to set the x and y coordinates to the speed variables ill post a working code in just a sec

Jerok
19
Years of Service
User Offline
Joined: 7th May 2005
Location: Mars. Wait a sec I\'m on MARS. OMG
Posted: 30th Mar 2006 04:16


Zombie dwarf
18
Years of Service
User Offline
Joined: 15th Mar 2006
Location:
Posted: 31st Mar 2006 18:13
oh right, thanks for the helps.

Login to post a reply

Server time is: 2024-11-27 01:44:35
Your offset time is: 2024-11-27 01:44:35