-mouseMoved OSX does not get called in a sprite kit SKScene

余生长醉 提交于 2019-12-05 16:21:50

Add to the app delegate:

_window.acceptsMouseMovedEvents = YES;
[_window makeFirstResponder:self.skView.scene];

In swift

window.acceptsMouseMovedEvents = true;
window.makeFirstResponder(self.skView.scene)

You can get at the window object and set it from the scene.

in Swift: override func willMove(from view: SKView) { self.view!.window?.acceptsMouseMovedEvents = true }

The above answers either make too many assumptions about what’s outside of your SKScene, or add a touch of unnecessary hackiness by messing with the responder chain.

SKView is a subclass of UIView. It inherits, therefore, the viewDidMoveToWindow: method. You can activate mouse-moved events for all your SKViews with a simple extension.

extension SKView {
    open override func viewDidMoveToWindow() {
        super.viewDidMoveToWindow()
        window?.acceptsMouseMovedEvents = true
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!