【问题标题】:Xcode 7.2, iOS 8.X, SpriteKit, Sprite do not recognize any touchXcode 7.2、iOS 8.X、SpriteKit、Sprite 无法识别任何触摸
【发布时间】:2015-12-11 12:30:30
【问题描述】:

我已经开发了:

  • Swift 2.1.1(当前版本)和 SpriteKit 中的游戏
  • 我在 Xcode 7.2 上运行
  • OS X 10.11.2 (EL Capitan)
  • 游戏项目设置“部署目标”设置为 8.0。

在真正的 iPhone 6 设备和在 iOS 9.x 上运行的任何模拟器上一切正常。

但我需要在 iOS 8.x 上测试它,我只有这个版本的模拟器。游戏正常启动 - 一切看起来都很好,但我无法点击任何地方。无法识别点击/触摸。日志或 Xcode 中没有错误。我不知道是什么问题,模拟器还是我的游戏。

有人有类似的问题吗?感谢您的建议。

编辑: 经过一番研究,我发现 iOS 8 存在错误:一个(全屏)具有属性 hidden=true 的精灵在我的可触摸精灵 - 按钮上方。这个全屏精灵“吸收”所有触摸。就算隐藏了。此错误已在 iOS 9 中修复。

有什么想法吗?

【问题讨论】:

标签: xcode swift sprite-kit touch ios-simulator


【解决方案1】:

我的解决方法:不仅要隐藏,还要从父精灵中移除。 我所有的精灵都是 MySpriteNode 的后代。在那个类中我实现了函数 setVisible(),实现:

func setVisible(visible:Bool, _ newParent:SKNode?)
{
    // hide sprite
    if !visible
    {
        self.hidden = true
        self.removeFromParent()
    }

    // show sprite
    else
    {
        self.hidden = false
        if newParent != nil && self.parent == nil
        {
            newParent!.addChild(self)
        }
        else
        {
            // Sprite is visible (with old parent)
        }
    }
}

如果我想隐藏精灵:

myButton.setVisible(false, nil)

如果我想展示精灵,我必须知道父母:

myButton.setVisible(true, self)

现在,触摸已成功识别。

【讨论】:

    猜你喜欢
    • 2014-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多