【发布时间】:2016-06-19 15:42:19
【问题描述】:
这是我尝试执行上述操作,但没有成功:
let square = SKShapeNode(rectOfSize: CGSize(width:60, height: 80))
var isConditionMet = false
override func didMoveToView(view: SKView) {
square.position.x = 0
square.position.y = 0
addChild(square)
var moveSquare:SKAction
moveSquare = SKAction.moveTo(CGPoint(x: 100, y: 100), duration: NSTimeInterval(5))
square.runAction(SKAction.sequence([moveSquare, SKAction.removeFromParent()]))
}
func checkThenChangePosition(shape:SKShapeNode) {
if isConditionMet == true {
shape.position.x = size.width
}
}
override func update(currentTime: CFTimeInterval) {
print(square.position.x)
if (square.position.x > 45) && (square.position.x < 50) {
isConditionMet = true
}
checkThenChangePosition(square)
}
使用上面的代码,我希望正方形从 (0,0) 开始并朝 (100,100) 移动。一旦正方形的位置介于 45 和 50 之间(通常在 45.5 左右,因为 SKAction 不会将正方形移动整数值),正方形应该从其当前 x 位置更改为 size.width 的值(在 iPhone 6 上)模拟器是 375.0)。
然而,事实并非如此。相反,在 SKAction 完成之前,正方形不会移动到 x = 375.0(一旦正方形达到 (100,100))。有什么办法可以让方块在运行SKAction的过程中改变位置,然后继续运行SKAction。基本上我希望正方形从 x = 0 移动到 45
【问题讨论】:
标签: swift sprite-kit skaction