1
好吧,這是令人沮喪的,因爲這不應該這麼難。無論何時用戶將手指放下,我需要我的精靈節點永遠向一個方向移動。在這裏,我創造我的精靈節點無法讓Spritenode永遠向一個方向移動?
character.size = CGSize(width: 58, height: 139)
character.color = UIColor.red
character.position = CGPoint(x: (scene?.size.width)!/2, y: (scene?.size.height)!/2)
character.zPosition = 3
character.physicsBody = SKPhysicsBody(rectangleOf: character.size)
character.physicsBody?.isDynamic = true
character.physicsBody?.affectedByGravity = false
character.physicsBody?.allowsRotation = false
然後在接觸開始,我曾嘗試直接施加力,並具有觸摸時結束了被刪除重複skaction,但是使用SKaction.moveBy,節點移動10再扣回到原來的位置:
override public func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
print("touch!")
isTouching = true
let touch = touches.first!
//
let movement = CGVector(
dx: 10,
dy: 1
)
let move = SKAction.moveBy(x: character.position.x+10, y: 0, duration: 1)
//let move = SKAction.applyForce(movement, duration: 0.5)
character.run(SKAction.repeatForever(move), withKey: "moving")
我使用character.position.x,所以我不知道它爲什麼不只是永遠移動到正確的位置。如何讓節點在一個方向上連續移動?
與http://stackoverflow.com/q/41220072/1430420相似嗎? –