简体   繁体   中英

How to set a custom cursor at the launch of an OSX spritekit app?

So I want to use a custom cursor in my spritekit game. I've only been 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've clicked twice and moved the mouse. What I really want is to have the new cursor show up as soon as the app launches. Any ideas? Adding the cursor in ApplicationDidFinishLaunching isn't working.

It worked for me by putting your code into sprite kit's didMoveToView function:

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)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM