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 / Joystick fire button state seems too rapid to track

Author
Message
Fuzzzy Piggy
18
Years of Service
User Offline
Joined: 2nd Mar 2006
Location:
Posted: 7th Nov 2006 07:47
Running DBPro, v6 patched. I have spent nearly two hours going around in circles on this one, I know I am doing something stupid, but I just need someone to wake me up a bit!

I have a sprite up on the screen and the sprite drops bombs. The sprite movement with joystick is fine, the bomb drop with the joystick button is fine, BUT the joystick button, unlike mouse button, obviously only has one state, that is repeatedly on. When I push the joystick button inside the game loop, it fires so rapidly that all the objects the sprite has get dumped straight away.

I have tried in various ways to mimic the button up/down tracking but still nothing. How do I track that the button is down, maybe held down and then let go? So basically any push of the button, no matter how long, it still classed as a single action, until the button is released and presed again for a seconde single action and so on.

Any help much appreciated in advance.

Common-Sense has been removed from service, due to lack of interest. Thank you for your time.
CreamPie
18
Years of Service
User Offline
Joined: 20th Jul 2006
Location:
Posted: 7th Nov 2006 11:12
Fuzzzy Piggy,

Okay, the focus is to allow execution of the bomb dropping command, only once when the trigger button is pressed. Therefore, before executing the command we must check to see what if trigger was pressed on the last program loop.

If the trigger was not pressed on the last loop, but is now pressed on the current loop, we come to an initial press. Then, the command is executed. But, on the next loop(knowing that several program loops can pass during the duration of the physical press of a button ), though the trigger might be currently pressed, it was also pressed on the last loop. So, the command will not execute.

In code, we store a variable, oldfirebuttonstate, with the value of the joystick fire button state, for the current loop. On the next loop, the code will swing around to the section containing the detection of the keypress. At this point, you not only check for the a current keypress, but you also check the value that is inside of oldfirebuttonstate. If it contains a 1, then the command is not executed. Else, it is.

Below is a code example(though code is for DarkBasic Classic, I am sure it should be easily convertible to DB Professional).

Fuzzzy Piggy
18
Years of Service
User Offline
Joined: 2nd Mar 2006
Location:
Posted: 7th Nov 2006 20:34
Blinding stuff! I almost had it, but for some stupid reason I kept checking for a value of 1 on my "tracker" variable! DuH!

Thank you very much indeed for your time and advice!

Common-Sense has been removed from service, due to lack of interest. Thank you for your time.

Login to post a reply

Server time is: 2024-09-25 11:33:25
Your offset time is: 2024-09-25 11:33:25