swift - SKAction 不适用于 overlaySKScene?

标签 swift sprite-kit scenekit

我熟悉运行 SKActions 并且从未遇到过问题。

但这就是问题所在,我的主要游戏是在带有 SceneKit 的 ARKit 中,我在顶部添加了一个 SpriteKit 覆盖层以显示一些 HUD:

sceneView.overlaySKScene = scene
sceneView.overlaySKScene?.isUserInteractionEnabled = false
sceneView.overlaySKScene?.scaleMode = .aspectFit

2D HUD 显示正确,我可以通过代码移动位置、旋转、缩放,但我无法运行任何动画(即使从代码创建节点并将它们添加为子节点):

class OverlaySKScene: SKScene {

    override func didMove(to view: SKView) {
        someSprite = childNode(withName: "someSprite") as! SKSpriteNode
        someSprite.run(SKAction.rotate(byAngle: CGFloat.pi, duration: 1.0))     
    }
}

最佳答案

根据docs , SKScene.isPaused 应该设置为 false:

If the value is true, the scene’s content is fixed onscreen. No actions are executed and no physics simulation is performed. When an application moves from an active to an inactive state, isPaused is automatically set to true. When an application returns to an active state, isPaused is automatically set to its previous value.

这有点解释了为什么如果您在 Xcode 中暂停/取消暂停场景时它会运行这些操作...“事件状态”会发生变化。

因此,在设置 overlaySKScene 之后,您必须记住将其 isPaused 属性设置为 false。这让 Action 开始运行,但现在问题变得非常奇怪。我有一个基本的 SKSpriteNode 在我的 Scene.swift 中声明为 frigidityBar。在 Scene.sks 中使用名为“frigidityBar”的 SKSpriteNode 的典型设置。

 var frigidityBar: SKSpriteNode!

像这样对其运行操作是行不通的:

    frigidityBar!.run(SKAction.colorize(with: SKColor.orange, colorBlendFactor: 1.0, duration: 1.0)) {
        print("Colorize action did run!")
    }

但这确实如此。

    displayNode.childNode(withName: "frigidityBar").run(SKAction.colorize(with: SKColor.orange, colorBlendFactor: 1.0, duration: 1.0)) {
        print("Colorize action did run!")
    }

就像这样:

    (frigidityBar as SKNode).run(SKAction.colorize(with: SKColor.orange, colorBlendFactor: 1.0, duration: 1.0)) {
        print("Colorize action did run!")
    }

即使完全转换为 SKSpriteNode 也会失败:

  (frigidityBar as SKSpriteNode).run(SKAction.colorize(with: SKColor.orange, colorBlendFactor: 1.0, duration: 1.0)) {
        print("Colorize action did run!")
    }

我不期待这里有任何 Elixir ,但欢迎任何想法、预感或猜测。

关于swift - SKAction 不适用于 overlaySKScene?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49887794/

相关文章:

swift - 绕一整圈时节点的方向是错误的

swift - 我可以使 SCNBox 可点击并进行交互吗?

ios - Swift - 初始化 UITableViewCell

ios - 在 ViewController 循环中隐藏/显示 TabBar

swift - 如何从 Swift 中数组的第一项中获取字典项的值?

swift - Swift 中的实体组件

cocoa - 从 NSTextView 中删除文本

swift - 删除 SKAction 并恢复节点状态

swift - SKVideoNode帧率

iOS 10 : SCNLight of type Omni ignoring attenuation values?