【发布时间】:2016-08-03 16:35:49
【问题描述】:
当我按下屏幕上的按钮时,我试图将精灵向右移动。但是,当我尝试这样做时,我只有将精灵移动到某个点的解决方案。所以...我希望精灵永远向右移动,或者直到我做其他事情。
这是在 Xcode 中使用 SpriteKit 中的 Swift。
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch : AnyObject in touches{
let pointInTouch = touch.locationInNode(self)
let tappedNode = nodeAtPoint(pointInTouch)
let tappeNodeName = tappedNode.name
if tappeNodeName == "Btn"{
player.physicsBody?.velocity = CGVectorMake(0, 0)
let action = SKAction.applyImpulse(CGVectorMake(400, 0), duration: 1)
player.runAction(SKAction.repeatActionForever(action))
print("Touched!")
}
}
}
【问题讨论】:
-
你想永远向右移动精灵,但是当它退出场景并且不再可见时会发生什么?
标签: swift xcode sprite-kit