Cocoa: Mouse x and y

Post: #1
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,
Quote this message in a reply
Post: #2
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.
Quote this message in a reply
Post: #3
i usually do somthing (from an NSView) like :

[NSEvent mouseLocation].x-[[self window] frame].origin.x-[self frame].origin.x
[[self window] frame].size.height-([NSEvent mouseLocation].y-[[self window] frame].origin.y-[self frame].origin.y)
Quote this message in a reply
Post: #4
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...
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  changing mouse icon in cocoa Leroy 13 11,358 Sep 4, 2007 07:10 PM
Last Post: SethWillits
  Mouse coordinates with Cocoa vnvrymdreglage 13 10,396 Apr 8, 2007 07:26 AM
Last Post: vnvrymdreglage
  Cocoa: Mouse location while dragging window Fenris 4 7,263 Jul 14, 2005 04:46 PM
Last Post: Fenris
  Cocoa - Reset Mouse Position to center of View CactusJack 6 8,305 Dec 11, 2002 08:51 PM
Last Post: CactusJack