View Full Version : Cocoa: Mouse x and y
Phate
2002.12.13, 04:09 PM
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
furballphat
2002.12.13, 05:35 PM
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.
ededed
2002.12.15, 10:23 AM
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)
ededed, you might want to have a look at NSView's convertPoint:fromView: (http://developer.apple.com/techpubs/macosx/Cocoa/Reference/ApplicationKit/ObjC_classic/Classes/NSView.html#//apple_ref/occ/instm/NSView/convertPoint:fromView:) and convertPoint:toView: (http://developer.apple.com/techpubs/macosx/Cocoa/Reference/ApplicationKit/ObjC_classic/Classes/NSView.html#//apple_ref/occ/instm/NSView/convertPoint:toView:), as well as NSWindow's convertBaseToScreen: (http://developer.apple.com/techpubs/macosx/Cocoa/Reference/ApplicationKit/ObjC_classic/Classes/NSWindow.html#//apple_ref/occ/instm/NSWindow/convertBaseToScreen:) and convertScreenToBase: (http://developer.apple.com/techpubs/macosx/Cocoa/Reference/ApplicationKit/ObjC_classic/Classes/NSWindow.html#//apple_ref/occ/instm/NSWindow/convertScreenToBase:). Might help avoid all those subtractions...
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.