【问题标题】:Xcode 9: SKEditorReference doesn't allow animations?Xcode 9:SKEditorReference 不允许动画?
【发布时间】:2018-10-21 03:55:23
【问题描述】:

我似乎无法获取通过引用添加的精灵节点(将一个 sks 文件拖放到 Xcode 9 中的另一个 sks 文件中)以进行动画处理。这似乎是允许的,因为您可以在物理上做这样的事情,但我不确定为什么子节点不会动画。

示例 1.从标准的spritekit模板开始 2.添加一个HUD.sks文件,在某处添加一个颜色精灵,命名为“hudSpriteNode” 3. 将 HUD.sks 文件拖到 GameScene.sks 场景中 - 将其居中于零 4. 找到 hudSpriteNode(按名称) 5. 用 .position 移动它(有效!) 6. 用动画移动它(失败!)

HUD.sks

GameScene.sks

将此代码添加到 GameScene.swift

if let testSpriteNode = childNode(withName: "//hudSpriteNode") as? SKSpriteNode {
  print("Found test sprite node")
  print("Test node position 1: \(testSpriteNode.position)")
  testSpriteNode.position = CGPoint.zero
  print("Test node position 2: \(testSpriteNode.position)")
  testSpriteNode.run(SKAction.moveBy(x: 200, y: 200, duration: 4))
}

运行...位置移动正确,但动画失败。

【问题讨论】:

  • 当场景移动到视图时,尝试将场景的 isPaused 属性设置为 false。看看这里:stackoverflow.com/questions/47615847/…
  • 谢谢@Marcel。这主要通过我的一些额外更新/验证来解决问题。

标签: swift xcode animation


【解决方案1】:

参见 cmets 中 @Marcel 的链接。他指出我的帖子主要通过我的一些额外更新/验证来解决问题。不过,我能够让它工作的唯一方法是将 isPaused 放在我试图动画的确切精灵节点上(在我的 ref 节点内)。

我在顶层尝试了isPaused=false,主场景didMove查看,但没有效果,然后在主参考节点添加isPaused=false,没有效果。它仅在我添加 isPaused=false 时才起作用,我试图制作动画的实际精灵(在我添加的 ref 节点内)。我从主节点和 ref 节点中删除了 isPaused=false,只要 isPaused=false 仍在相关的 sprite 节点上(我试图动画的 ref 节点中的那个):成功。

底线似乎是引用节点中包含的任何精灵都需要 isPaused=false。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-12
    • 1970-01-01
    • 1970-01-01
    • 2021-02-07
    • 2014-11-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多