Another Mouse Issue? - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10) +---- Thread: Another Mouse Issue? (/showthread.php?tid=2621) Pages:
1
2
|
Another Mouse Issue? - NakedApe - 04-25-2024 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 RE: Another Mouse Issue? - SMcNeill - 04-25-2024 Mouse your mouse events outside the update loop: Code: (Select All)
This fixes any issues on my system. Honestly, the only thing that needs to go inside that WHILE_WEND loop is your scrollwheel code. RE: Another Mouse Issue? - Pete - 04-25-2024 My mouse routine without double or triple clicks, which I'll probably add tomorrow. Code: (Select All)
Multiple left clicks an be handled with a timer. Timer starts when the left button is pressed. If the button is released within the time, a flag is set to count 1. If not, no flag. If the flag was set the timer now tracks no-click time. If that set time, say .1 expires, the flag is canceled. The flag can be increased to some max like 3 for a triple click. Of course we could also just count click and release events during a .2-sec period. Get 3 click cycles completed and your triple clicked! I'll come back and update the code if I do add that to this routine tomorrow. I have a new graphics WP project I'm using this one in, but I haven't added double click to highlight one word or triple click to highlight the line, yet. Pete RE: Another Mouse Issue? - TerryRitchie - 04-25-2024 (04-25-2024, 01:06 AM)SMcNeill Wrote: Mouse your mouse events outside the update loop:LOL. Mouse your mouse events, cracked me up. I find myself doing these types of typos all the time. But Steve is correct, the only thing that should be done within a mouse update loop is gathering scroll wheel events. Here's a demo of that: Code: (Select All) SCREEN _NEWIMAGE(800, 600, 32) RE: Another Mouse Issue? - bplus - 04-25-2024 i approached that problem by timing bullets fired also you could limit number of bullets, waiting until bullet off screen before reactivating that bullet slot to fire again. RE: Another Mouse Issue? - TerryRitchie - 04-25-2024 (04-25-2024, 01:42 AM)bplus Wrote: i approached that problem by timing bullets firedI use a similar approach. The code below is a snippet from my Widescreen Asteroids game that controls bullet fire. I tend to set up frame counters as timers. In the second line of code I first check to see if Clock.shipBullet is zero. If it is that means I can fire again. If not toward the end of the snippet you'll see I decrement Clock.shipBullet by one with each passing frame. The game runs at 60 frames per second and setting Clock.shipBullet to 10 after each bullet fired ensures that the player can fire no more than 6 bullets per second. Code: (Select All)
RE: Another Mouse Issue? - NakedApe - 04-25-2024 Steve and Terry, thank you, but I'm on a Mac, the neglected step-child platform , and moving the mouse events outside the update loop is different. Doing your fix, Steve, doesn't solve the problem for me, it just made the timer not work at all 'cept for the beep. Terry, your demo doesn't work on my system either. Pete, thanks, I'll give your sub a try, but I have my doubts. bplus, I'm not using bullets here, just a laser beam to blast away. Terry, I'll try the method from your latest post - cycle counting makes sense. Thanks, everybody. RE: Another Mouse Issue? - TerryRitchie - 04-25-2024 (04-25-2024, 02:16 AM)NakedApe Wrote: Steve and Terry, thank you, but I'm on a Mac, the neglected step-child platform , and moving the mouse events outside the update loop is different. Doing your fix, Steve, doesn't solve the problem for me, it just made the timer not work at all 'cept for the beep. Terry, your demo doesn't work on my system either. Pete, thanks, I'll give your sub a try, but I have my doubts. bplus, I'm not using bullets here, just a laser beam to blast away. Terry, I'll try the method from your latest post - cycle counting makes sense. Thanks, everybody.My demo doesn't work on a Mac? That sounds like an issue with QB64pe that needs looking into. RE: Another Mouse Issue? - bplus - 04-25-2024 'bplus, I'm not using bullets here, just a laser beam to blast away.' semantics: bullet/laser beam, is it a wave or is it a particle? it's both! just time the 'lastBeam' and don't fire another until > your spec'd time period how come you aren't giving Terry this bs about bullets, lol btw i have recently heard nobel prize went to physics that proved it is neither wave nor particle until it is observed, really spooky stuff, then it IS particle referring to double slit experiment with light ie when 'observed' there is no interference pattern. of course i am getting this info from wacky gia you tube??? RE: Another Mouse Issue? - NakedApe - 04-25-2024 Terry, I think the lack of mouse wheel support on macOS is a known issue, but maybe a740g could comment on that. bplus, you are so right. I fixed the issue without using timers. Cycle counting, which I already used elsewhere in the program, was a simple fix - duh. There's almost always another way to get a job done with QB if you think about it - and get help from the hive mind here. |