Jump to content
  • Advertisement

Nistan

Member
  • Content Count

    5
  • Joined

  • Last visited

Community Reputation

110 Neutral

About Nistan

  • Rank
    Newbie
  1. 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 } }
  2. Why? Thats exactly where my problem is. The original plan was to increase the force as long as the screen is tapped until the maximum, but the force should be applied meanwhile and not after. But If I keep track in the update method or elsewhere, the increased force will be implied the next time the screen is touched, not while the screen is touched.
  3. Yes, because I need to keep track of the Minimum and Maximum Force. The Player does not only jump after maximum Jump, but also in between minimum and maximum. The only problem I face is that I want to have the Player jumping, and the longer you tap the longer the jump will be, but you cant change the force the Player jumped after the jump has happend/ while the jump is happening.
  4. The self.pressed is for whenever the Player is on ground again, while the Screen is still touched, he jumps again.  
  5. Hello, I want to increase a CGFloat while a tap is going on. There is a Player node, which should always jump after the Screen is tapped. But the Player should have a minimum and a maximum jump, and also can jump between those set constants. The longer the Screen is touched, the longer the jump until the maximum Jump, but this should go while the Screen is touched, not after.   With my Code, the Player jumps after the Screen is touched or after the maximum Jump is true.   func jump(force : CGFloat){                           if(self.isCharacterOnGround){                          self.Player.physicsBody?.applyImpulse(CGVectorMake(0, force))             self.isCharacterOnGround = false         }              }          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)                          self.pressed = true                          let timerAction = SKAction.waitForDuration(0.0)                          let update = SKAction.runBlock({                 if(self.force < Constants.maximumJumpForce){                     self.force += 2.0                 }else{                     self.jump(Constants.maximumJumpForce)                     self.force = Constants.maximumJumpForce                 }             })             let sequence = SKAction.sequence([timerAction, update])             let repeat = SKAction.repeatActionForever(sequence)             self.runAction(repeat, withKey:"repeatAction")         }     }          override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {         for touch in (touches as! Set<UITouch>) {             let location = touch.locationInNode(self)                          self.removeActionForKey("repeatAction")                          self.jump(self.force)                          self.force = Constants.minimumJumpForce                          self.pressed = false                  }     }      override func update(currentTime: NSTimeInterval) {      }
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!