如果我在节点上创建SKSpriteNode
并运行SKAction
,则该操作将在模拟器上运行,但该节点的属性未更改。 例如在下面的例子中,在模拟器中,节点从(50,50)开始并在1秒内移动到(0,0)。然而,在最后打印的打印语句(50,50),而不是新的位置(0,0)Xcode SpriteKit SKAction不改变SKSpriteNode的属性?
let test = SKSpriteNode()
test.position = CGPoint(x: 50.0, y: 50.0)
test.size = CGSize(width: 20.0, height: 20.0)
test.color = UIColor.black
addChild(test)
test.run(SKAction.move(to: CGPoint(x: 0, y: 0), duration: 1.0))
print("(\(test.position.x), \(test.position.y))")
我能想到的唯一理由是,在执行之前SKAction
print语句执行。如果是这种情况,那么我该如何执行后面的代码才能获取SKSpriteNode
的位置值?
您不需要添加更多'SKAction'来打印位置 –