lundi 23 mars 2015

recognizing long press gesture in spriteKit

Hi I am currently moving a sprite by checking if the button was pressed in touchesBegan and then updating the position in update. I am doing this so that the user does not need to keep pressing the move up/down/left/right etc button over and over. The problem is that sometimes the sprite does not stop moving which im sure is due to this. Does anyone know a better solution to this? For brevity I will show you the way I am taking care of the up button.



override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {

for touch: AnyObject in touches {
// Get the location of the touch in this scene
let location = touch.locationInNode(self)
// Check if the location of the touch is within the button's bounds
if upButton.containsPoint(location) {
upButtonPressed = true
}



override func update(currentTime: CFTimeInterval) {
if upButtonPressed == true {
ball.position.y += 3
}


I kept it simple here but I do have all the conditions to stop movement in my code. I am simply wondering if there is an easier way to do this with maybe a long press gesture recognizer?




Aucun commentaire:

Enregistrer un commentaire