Monkey
Store
Community
Apps
Contact
Login or Signup

MouseX() MouseY() or store inside variable ?

Monkey Programming Forums/Monkey Programming/MouseX() MouseY() or store inside variable ?

GC-Martijn(Posted 1+ years ago) #1
Is it a good idea to store the MouseX() and MouseY() inside a Float ?
And use that every loop ?

Something like this.
- main loop
update(){
myMouseX = MouseX()
myMouseY = MouseY()

- other classes
uses now myMouseX and myMouseY
}

Or are there some small Mouse xy updates inside the same loop, so I have to use MouseX() and MouseY()



Then a bonus question ;)
------------------------------------------------
Is it always slow when I do something like this

- main loop
update(){
myMouseX = MouseX()
myMouseY = MouseY()
}
render(){
draw(rect,myMouseX,myMouseY)
}

When you move the mouse over the screen, the rect is slow moving with a delay (fps(30) and fps(60)) using html5
------------------------------------------------

Thanks,


Gerry Quinn(Posted 1+ years ago) #2
I generally just read them once at the start of the update method. I suspect it will make for greater consistency if nothing else. You run no risk of clicking two buttons (in different places) in the same update, for example.

But I also doubt whether it will really matter in most situations.


zoqfotpik(Posted 1+ years ago) #3
You could write a wrapper for MouseX(), MouseY() that would check to see if it had already recorded the position this tick.

If not, then it would record the position.

Then it would return either new mouse position or the mouse position already recorded.


Gerry Quinn(Posted 1+ years ago) #4
It will return that whether it checks or not!

Edit: Oops, sorry, I see your point now.


Samah(Posted 1+ years ago) #5
From what I can see, Android, GLFW, XNA, and PSS update all input values at the beginning of the frame (before OnUpdate() is called).

iOS's touch updates are called from the touches(Action):withEvent: methods in UIWindow, which I assume runs on a separate thread, so I can't guarantee that they are updated exactly once per frame.

Flash input updates are event-based, but since Flash is not multi-threaded and the rendering/update is also an event (Event.ENTER_FRAME), there shouldn't be any concurrency problems with retrieving input.

HTML5 updates seem to also be event-based, but since HTML5/JS is also single-threaded (apart from web workers) you shouldn't have a problem.


jpoag(Posted 1+ years ago) #6
iOS touch events are forwarded to the app delegate (defined in mojo.ios.cpp) which is in turn forwarded to the gxtInput class for caching.

Events (touch, etc..), Timers (Update() Loop), etc... all run as phases of the NSRunLoop.

For better details, read up on NSRunLoop, or CFRunLoop

https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Multithreading/RunLoopManagement/RunLoopManagement.html#//apple_ref/doc/uid/10000057i-CH16