Cocoa: Mouse x and y
Sorry, this is probably a really newbie question, but I'm now moving into Cocoa (after almost 2 years in Real Basic) and I've got a simple sidescroller in the works, I have the key input working fine, but I can't find how I get the mouse X and Y (in RB i just had to check system.mouseX/system.mouseY), i would prefer if it was window-relative (so you could choose to play the game in a windowed mode), but screen relative would be fine too (then you'll be forced to play it full screen).
Thanks for any help,
Phate
Thanks for any help,
Phate
Look around in NSEvent for getMouseLoctionInWindow. The number of times this (and questions about setting the mouse location) have been asked definitely warrant an FAQ entry.
i usually do somthing (from an NSView) like :
[NSEvent mouseLocation].x-[[self window] frame].origin.x-[self frame].origin.x
and
[[self window] frame].size.height-([NSEvent mouseLocation].y-[[self window] frame].origin.y-[self frame].origin.y)
[NSEvent mouseLocation].x-[[self window] frame].origin.x-[self frame].origin.x
and
[[self window] frame].size.height-([NSEvent mouseLocation].y-[[self window] frame].origin.y-[self frame].origin.y)
ededed, you might want to have a look at NSView's convertPoint:fromView: and convertPoint:toView:, as well as NSWindow's convertBaseToScreen: and convertScreenToBase:. Might help avoid all those subtractions...
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| changing mouse icon in cocoa | Leroy | 13 | 5,725 |
Sep 4, 2007 07:10 PM Last Post: SethWillits |
|
| Mouse coordinates with Cocoa | vnvrymdreglage | 13 | 6,088 |
Apr 8, 2007 07:26 AM Last Post: vnvrymdreglage |
|
| Cocoa: Mouse location while dragging window | Fenris | 4 | 4,492 |
Jul 14, 2005 04:46 PM Last Post: Fenris |
|
| Cocoa - Reset Mouse Position to center of View | CactusJack | 6 | 5,598 |
Dec 11, 2002 08:51 PM Last Post: CactusJack |
|

