How to move the object only when it's clicked?
-
I feel like I'm close to the target! The object only responds to the evidence on its own, but only moves along its borders... How do I fix it?
import SpriteKit
class GameScene: SKScene {
//создаем свойство
var figureUser = SKSpriteNode!()override func didMoveToView(view: SKView) {
//инициализируем свойство figureUser = SKSpriteNode(imageNamed: "circle") //определяем позицию square на экране figureUser.position = CGPoint(x: 25, y: 25) //даем имя figureUser.name = "circle" figureUser.userInteractionEnabled = false //добавляем square на экран addChild(figureUser)
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
let touch = touches.first let touchLocation = touch!.locationInNode(self) let node = self.nodeAtPoint(touchLocation) if (node.name == "circle") { let moveAction = SKAction.moveTo(touchLocation, duration: 0) figureUser.runAction(moveAction) }
}
}
-
I asked and answered it myself. ) For
touchesBegan
We need to use it.touchesMoved
♪