How do I set a custom cursor when running a spritekit OSX application?
So I want to use a custom cursor in my spritekit game. I was only able to get it to work by adding this to my first scene:
override func mouseEntered(theEvent: NSEvent) {
let myCursor: NSCursor = NSCursor(image: NSImage(named: "cursor")!, hotSpot: NSPoint(x: 0.5, y: 0.5))
self.view?.addCursorRect(self.frame, cursor: myCursor)
}
However, this doesn't change the cursor to my custom one until I double-clicked and moved the mouse. I really want the new cursor to be displayed as soon as the application starts. Any ideas? Adding cursor to ApplicationDidFinishLaunching doesn't work.
+3
source to share
1 answer
This worked for me by putting your code in the didMoveToView help kit:
override func didMoveToView(view: SKView) {
super.didMoveToView(view)
// Show custom mouse cursor
let myCursor: NSCursor = NSCursor(image: NSImage(named: "cursor")!, hotSpot: NSPoint(x: 0.5, y: 0.5))
self.view!.addCursorRect(self.frame, cursor: myCursor)
}
0
source to share