04-25-2024, 12:54 AM
I'm working on a game, see, and I don't want the player to be able to hold down the fire-button indefinitely (that's cheating!). So I tried setting up a timer that kills the left mouse button after a second and a half. All is cool if the mouse is stationary, but the minute you move the mouse the button resets itself - without the user letting the button up - not cool. Is this a Mac mouse issue, a QB64PE mouse issue or a dumb NakedApe issue?
Is there a better way to do this?
Thanks in advance for any insights, Ted
DIM AS _BYTE leftClick, started
DIM startTime AS LONG
SCREEN _NEWIMAGE(800, 600, 32)
DO
WHILE _MOUSEINPUT
leftClick = _MOUSEBUTTON(1) '
mouseX = _MOUSEX
mouseY = _MOUSEY
WEND
IF leftClick THEN
IF NOT started THEN startTime = TIMER: started = -1
IF TIMER - startTime > 1.5 THEN ' no holding the button down forever!
leftClick = 0 ' kill left click
started = 0 ' reset timer
SOUND 1000, .7 ' pip
END IF
_PRINTSTRING (380, 280), "Button Down"
_PRINTSTRING (380, 320), STR$(TIMER - startTime)
END IF
IF NOT leftClick THEN ' if buttonUP then reset timer and erase
CLS
started = 0
END IF
LOOP UNTIL _KEYDOWN(27)
SYSTEM
Is there a better way to do this?
Thanks in advance for any insights, Ted
DIM AS _BYTE leftClick, started
DIM startTime AS LONG
SCREEN _NEWIMAGE(800, 600, 32)
DO
WHILE _MOUSEINPUT
leftClick = _MOUSEBUTTON(1) '
mouseX = _MOUSEX
mouseY = _MOUSEY
WEND
IF leftClick THEN
IF NOT started THEN startTime = TIMER: started = -1
IF TIMER - startTime > 1.5 THEN ' no holding the button down forever!
leftClick = 0 ' kill left click
started = 0 ' reset timer
SOUND 1000, .7 ' pip
END IF
_PRINTSTRING (380, 280), "Button Down"
_PRINTSTRING (380, 320), STR$(TIMER - startTime)
END IF
IF NOT leftClick THEN ' if buttonUP then reset timer and erase
CLS
started = 0
END IF
LOOP UNTIL _KEYDOWN(27)
SYSTEM