簡體   English   中英

如何在啟動OSX spritekit應用程序時設置自定義光標?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM