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 / DBC detecting when key is no longer being pressed

Author
Message
demons breath
21
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 28th Aug 2006 00:55 Edited at: 28th Aug 2006 01:12
basically like i said in my last post, i'm just trying to get used to the language again and i don't really know what i'm doing

but anyway this is my code:



my problem is, when i press the down button it just shoots to the bottom of the picture... i think this is probably because it keeps adding one until you let go of the down key but i'm not sure... but anyway how do i fix this? is there some simple code i can put in so that it doesn't execute the command until the down key is released?

EDIT: i just updated the code above... i've added in an upkey() and a leftkey() and that works how i want it to, with the movement slow instead of just shooting to the other place, but the rightkey() i added does that same thing... i don't know what i've done wrong

RIP Dimebag
http://db1games.topcities.com
(used to be demonsbreath)
D Ogre
21
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 28th Aug 2006 01:54
You could try using SCANCODE() and KEYSTATE() for yor keyboard inputs.
demons breath
21
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 28th Aug 2006 16:12
no luck

i'm a bit stuck on thisn i don't know why the up and down are behaving differently, as the code is almost identical...

RIP Dimebag
http://db1games.topcities.com
(used to be demonsbreath)
Ginga
18
Years of Service
User Offline
Joined: 3rd Jul 2006
Location: Dorset, England
Posted: 28th Aug 2006 20:22
ok .. i had a slight problem with a similar thing .. I managed to get around it by adding 'Wait 50' near the end, that way, if the key is still being pressed after the time alotted, it will continue again, else move on.

EXAMPLE for upkey



Hope it helps
demons breath
21
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 28th Aug 2006 21:21
thanks but i already tried that... it just made a little delay before updating the screen, it still just jumped to the bottom of the grid.

RIP Dimebag
http://db1games.topcities.com
(used to be demonsbreath)
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 28th Aug 2006 21:38
From what I can tell ... your title is a little miss-leading. It seems to me that you don't want to detect if a key is no longer pressed but rather, you want to move a sprite slowly while the key is being pressed.

This should do it:



Adjust the PAUSE variable to change the sprites speed in milliseconds.


Zergei
19
Years of Service
User Offline
Joined: 9th Feb 2005
Location: Everywhere
Posted: 28th Aug 2006 21:44
I know why this is done.
Your checking the array from left to right, up to down. So when you reposition it , say 1 tile lower, on the next loop it will find it there, so it will lower it once again, and then again and again.

How to solve it?... well, i'd do it by, instead of repositioning within the for/next loops, do it outside of it, but you could also exit from the for/next loop once you've done the moving operation. Do it by assigning "f" and "t" their proper max values, like this:



I know that up and right works ok, but it is best to exit the loop, and not make the cpu work needless operations.

Further on my stuff at...

Login to post a reply

Server time is: 2024-11-26 11:54:02
Your offset time is: 2024-11-26 11:54:02