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 / Keyboard too FAST???

Author
Message
ZEDi Knight
18
Years of Service
User Offline
Joined: 12th Apr 2006
Location:
Posted: 25th Jan 2007 21:49
hi,

I am making a Zelda DS style 2D game and my sprites shoot of the screen. The keyboard seems to be too fast. Do I need to insert a delay?

M.

sync on : sync rate 60

do
Rem move the player with right arrow key
if player_x < width
if rightkey() = 1 then gosub go_right
endif
if player_x > 1
if leftkey() = 1 then gosub go_left
endif
if player_y > 1
if upkey() = 1 then gosub go_up
endif
if player_y < height
if downkey() = 1 then gosub go_down
endif
Rem update the player
worldmap(player_y, player_x) = player_id

gosub render_game

sync

loop

Rem R = Rx Ry Rz
Gil Galvanti
19
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 25th Jan 2007 23:35
no you just need to decrease the speed at which you move your sprites .

Pirates of Port Royale
Live the life of a pirate.
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 26th Jan 2007 01:28
You can add a delay with the "timer()" command. Using "timer()" makes sure the delay is consistently accurate.

I changed your code around a bit. It's better to check for the key and the delay first then do a check to see if it's within the bounds of the screen. If the routines for actually moving the player aren't that big I suggest you remove the "gosub"s and put the actual moving code within the arrow key checking. There's no need to go somewhere else to do what you can do right where you are.

It's also indented your code. Indenting helps us to prevent and quickly find those annoying nesting errors. Its makes code easier to read too.



Login to post a reply

Server time is: 2024-11-26 21:40:30
Your offset time is: 2024-11-26 21:40:30