Using MouseX and MouseY

BlitzMax Forums/BlitzMax Beginners Area/Using MouseX and MouseY

*(Posted 2012) [#1]
When using MouseX or MouseY store the values in global variables then when you want to check against them you just check, it can be very time consuming for instance I have a loop that comes in at 2ms to render all the graphics for me game adding the calls to work out where the mouse is when required (this is two calls each to mouseX and mouseY) causes it to jump to 68ms.

Before everyone jumps on it I remmed out the line and its back to 2ms, the only thing changing was that line.

the line was this if statement:
if MouseX()>ScreenX-1 and MouseY()>ScreenY-1 and MouseX()<ScreenX+32 and MouseY()<ScreenY()+32
.
.
Endif


As you can see nothing out of the ordinary.

If you want to check you functions do something like:
Local MySec:Long = Millisecs()
YouFunctionHere()
Print "Time taken to run 'YourFunctionHere()' is "+String( Millisecs() -MySec )+"ms"


:)


ima747(Posted 2012) [#2]
Better still would be to put mouseX and Y in local variables you hand to sub functions that need them. depends on your structure if it's worth the savings though...

If you're grabbing mouse and storing it that means those values will still be set at the start of the next loop, meaning you can easily get movements from frame to frame giving you speed essentially etc. Lots of good stuff can be done with cached values and if you're caching them.