【问题标题】:Swift MacOS SpriteKit rightMouseDragged not workingSwift MacOS SpriteKit rightMouseDragged 不起作用
【发布时间】:2019-08-11 16:04:50
【问题描述】:

我有一个带有 SpriteKit 场景的 NSViewController/NSView 填充整个视图。以下是我需要处理的事件:

override func mouseDown(with event: NSEvent) {
override func rightMouseDown(with event: NSEvent) {
override func otherMouseDown(with event: NSEvent) {
override func mouseDragged(with event: NSEvent) {
override func rightMouseDragged(with event: NSEvent) {
override func otherMouseDragged(with event: NSEvent) {

但它们非常不一致,我根本无法让 rightMouseDragged 正常工作。

mouseDown works fine in the SKScene
rightMouseDown works fine in the SKScene
otherMouseDown had to be implemented in the viewController and passed on to the scene
mouseDragged worked fine in the SKScene
rightMouseDragged is not working at all
otherMouseDragged had to be implemented in the viewController and passed on to the scene

我的主要需要是修复 rightMouseDragged。它不会在视图控制器或场景控制器中接收任何拖动事件。

【问题讨论】:

  • 您的代码中还有其他内容导致了此问题。如果您创建一个新的 SpriteKit 项目并覆盖 GameScene 上的 rightMouseDragged 方法,则可以正常工作。 override func rightMouseDragged(with event: NSEvent) {print(#function)}
  • 确认它适用于默认项目。现在详细查看差异。在打印语句中使用#function 也很酷。

标签: swift macos cocoa sprite-kit


【解决方案1】:

好的,我不明白为什么,但是 rightMouseDragged 被传递到 SKView。所以这里是我需要实现我的事件处理程序的地方:

mouseDown in the SKScene
rightMouseDown in the SKScene
otherMouseDown in the viewController and passed on to the scene
mouseDragged in the SKScene
rightMouseDragged in the SKView and be passed to the scene
otherMouseDragged in the viewController and passed on to the scene

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多