Cocoa: Mouse x and y

Phate
Unregistered
 
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,
Phate
Quote this message in a reply
furballphat
Unregistered
 
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
ededed
Unregistered
 
Post: #3
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)
Quote this message in a reply
blb
Unregistered
 
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 6,601 Sep 4, 2007 07:10 PM
Last Post: SethWillits
  Mouse coordinates with Cocoa vnvrymdreglage 13 6,596 Apr 8, 2007 07:26 AM
Last Post: vnvrymdreglage
  Cocoa: Mouse location while dragging window Fenris 4 4,970 Jul 14, 2005 04:46 PM
Last Post: Fenris
  Cocoa - Reset Mouse Position to center of View CactusJack 6 6,201 Dec 11, 2002 08:51 PM
Last Post: CactusJack