![](/img/trans.png)
[英]How to set the window size and position programmatically for a SpriteKit/GameScene app on OSX
[英]How to set a custom cursor at the launch of an OSX spritekit app?
所以我想在我的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)
}
但是,在我单击两次并移动鼠标之前,这不会将光标更改为我的自定义光标。 我真正想要的是在应用程序启动后立即显示新光标。 有任何想法吗? 在ApplicationDidFinishLaunching中添加游标不起作用。
通过将您的代码放入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.