Increasing CGFloat while Tap

Started by
9 comments, last by Nistan 8 years, 8 months ago

You need to rethink how you are doing this. L. Spiro is offering you good advice.

That is exactly where my problem lies! Every time the Screen gets tapped, the Player jumps with the amount of 'force = 500', then there is Long Press, which activates after

the Screen is touched longer than 2 frames, the 'force' gets += 300. But with this code, the first time the screen is touched long, the Player still jumps 'force = 500'. After the Player is able to jump again, and the screen is touched, then the Player gets an increased jump of how long the screen was pressed previously.

For example, here is a game video with the same jump logic:

Can you help me somehow out?

Here is the code of which i originally thought of:


func longPressed(longPress: UIGestureRecognizer) {
        
        if (longPress.state == UIGestureRecognizerState.Ended) {
            
            println("Ended")
            
            self.pressed = false
          
            
        }else if (longPress.state == UIGestureRecognizerState.Began) {
            
            println("Began")
            
            self.pressed = true
            
        }
        
    }
    
    override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
        /* Called when a touch begins */
        
        for touch in (touches as! Set<UITouch>) {
            let location = touch.locationInNode(self)
            
            Player.physicsBody?.applyForce(CGVectorMake(0, force))
            
        }
    }
    
    override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
        for touch in (touches as! Set<UITouch>) {
            let location = touch.locationInNode(self)
        
    }
    }
    
    override func update(currentTime: CFTimeInterval) {
        /* Called before each frame is rendered */
        
        if(self.pressed){
            
            force += 300
        }
    }

This topic is closed to new replies.

Advertisement