简体   繁体   English

如何在启动OSX spritekit应用程序时设置自定义光标?

[英]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. 所以我想在我的spritekit游戏中使用自定义光标。 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. 在ApplicationDidFinishLaunching中添加游标不起作用。

It worked for me by putting your code into sprite kit's didMoveToView function: 通过将您的代码放入sprite kit的didMoveToView函数,它对我有用:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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