Answer the question
In order to leave comments, you need to log in
How to move an object only when you click on it?
I feel that I am already close to the goal! ) The object reacts only on a click on itself, but also moves only along its border .... How to 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)
}
}
}
Answer the question
In order to leave comments, you need to log in
He asked and answered himself. ) Instead of touchesBegan, you need to use touchesMoved.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question