Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 如何在OSX spritekit应用程序启动时设置自定义光标?_Swift_Macos_Sprite Kit_Cursor - Fatal编程技术网

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

Swift 如何在OSX spritekit应用程序启动时设置自定义光标?,swift,macos,sprite-kit,cursor,Swift,Macos,Sprite Kit,Cursor,所以我想在我的spritekit游戏中使用自定义光标。我只有在第一个场景中添加以下内容才能使其正常工作: 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, cu

所以我想在我的spritekit游戏中使用自定义光标。我只有在第一个场景中添加以下内容才能使其正常工作:

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

但是,在我单击两次并移动鼠标之前,这不会将光标更改为自定义光标。我真正想要的是在应用程序启动后立即显示新光标。有什么想法吗?在ApplicationIDFinishLaunching中添加光标不起作用。

将您的代码放入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)
}