Mouse Help Needed - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: QB64 Rising (https://staging.qb64phoenix.com/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://staging.qb64phoenix.com/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://staging.qb64phoenix.com/forumdisplay.php?fid=10) +---- Thread: Mouse Help Needed (/showthread.php?tid=306) |
RE: Mouse Help Needed - OldMoses - 05-02-2022 Of course, if one is only avoiding subs, the code would work just the same cut and pasted in the appropriate place, then substitute the mousebutton ID for 'var'. The only real point of the sub is to reduce typing redundancy, and the fact that QB64 is fast enough that the nested loop will probably work faster than any delay that would accommodate human fingers. I typically use Clear_MB # in anything that uses Steve's MBS function. My typical main program input loop looks like the following. I find it easy peasy, and I should probably put it in an include library. It works like a charm and I never have "click through" problems. (Note: the Clear_MB number is the mouse button number, not necessarily what MBS returns) Code: (Select All) DO 'main program display loop RE: Mouse Help Needed - SierraKen - 05-03-2022 That's interesting OldMoses, I added a PRINT "Mouse Button Pressed" right before the main loop ends. I saved this code in case I need it sometime, thanks! RE: Mouse Help Needed - SierraKen - 05-03-2022 Wow B+! I just added that SUB you just mentioned from OldMoses and your code to operate it replacing the _DELAYS and it works really good now! I'm going to think about adding something else before I make the next post on the main forum thread. I did post a version 1 or 2 days ago but this game is grabbing me to add more. RE: Mouse Help Needed - OldMoses - 05-04-2022 This is somewhat off topic, but thought you might be interested. Although you have the mouse sliders working well, I thought I'd introduce you to a little function that I learned a while back, which I think you will love. I think it was Fellippe that introduced me to the map! function. I use it for all sorts of conversions to translate screen positions to desired data ranges, but you'll find it useful for all sorts of things. When you collect the mouse data for power and angle you're doing the following two computations: vel = (mx - 60) / 200 * 100 ' converts place in box to 0 to 100 and a = (mx - 60) / 200 * 90 ' converts place in box to 0 to 90 Here, you're essentially doing the map function manually. Substituting the map! function, they become: vel = map!( mx, 60, 260, 0, 100) and a = map!( mx, 60, 260, 0, 90) No less typing of code, but you can shunt the math to the function and all you have to know is the input value from (in this case) mx, the left to right box limits and the desired range you want those limits translated to. In this way you don't have to reinvent the wheel for each different car. It will even reverse engineer the LINE statement from: LINE (61, 41)-(mx, 69), _RGB32(255, 0, 1), BF to LINE (61, 41)-(map!( vel, 0, 100, 60, 260), 69), _RGB32(255, 0, 1), BF ' returns mx from vel Which, in this case, doesn't really do anything in your favor, but just illustrates how it will work in either direction. Then you can place the following in the SUB/FUNCTION section of your code: Code: (Select All) FUNCTION map! (value!, minRange!, maxRange!, newMinRange!, newMaxRange!) Happy coding! RE: Mouse Help Needed - bplus - 05-04-2022 Heh, heh that was me doing the calc, I've done it so many times by hand I don't need Map! but yes! very handy for those who haven't had the practice! Thumbs up for mention of such a useful tool ! Hey too many !'s ? Never! I think instead of map it might be called Interpolate but that's probably scary term. map! (locate) this value = value! is between low = minRange and high = maxRange, as what value = map!'s return is between thisLow = newMinRange and thisHigh= newMaxRange? RE: Mouse Help Needed - OldMoses - 05-04-2022 What's most amazing about map! is how you can reverse the ranges. If you want a high value from a lower display position: vel = map!( mx, 60, 260, 100, 0) 'just flip the last two terms. RE: Mouse Help Needed - bplus - 05-04-2022 And you can probably use it for mouse position in a Windowed Screen if you forget Pmap keyword. RE: Mouse Help Needed - OldMoses - 05-05-2022 (05-04-2022, 05:12 PM)bplus Wrote: And you can probably use it for mouse position in a Windowed Screen if you forget Pmap keyword. That's probably the foremost reason I use map! rather than the PMAP command. I find it more intuitive because I can never remember which of the second function parameters (0-3) controls which translation of axis & direction. |