mardi 4 août 2015

Appling impulse on a SpriteKit node

I'm developing a SpriteKit Game,In which i have a node named hero who dodges the villains approaching,I have an issue in appyImpulse for a jump action and in this case user's can jump repeatedly and fly instead of dodging them,I used boolean variable to change the status with a timer value to jump only once in 3 seconds that is not working,And Im new to SpriteKit here is my code

override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
    if isGameOver == true {
        self.restart()
    }

    if isstarted {
        self.runAction(SKAction.playSoundFileNamed("jump.wav", waitForCompletion: false))
        for touch: AnyObject in touches{
            if jumpon == false {  //hero has not jumped
                    let location = touch.locationInNode(self)
                    heroAction()
                    jumpon = true   //hero jumped
            }
        }

    } else { 
        isstarted = true
        hero.stop()
        hero.armMove()
        hero.rightLegMove()
        hero.leftLegMove()
        treeMove()
        villanMove()
        let clickToStartLable = childNodeWithName("clickTostartLable")
        clickToStartLable?.removeFromParent()
        addGrass()
       // star.generateStarWithSpawnTime()
    }

}

func changeJump(){
    jumpon = false // hero has landed
}

and function update is called in every second and then changeJump must be called

 override func update(currentTime: CFTimeInterval) {

    if isstarted == true {
        let pointsLabel = childNodeWithName("pointsLabel") as MLpoints
        pointsLabel.increment()
    }

    if jumpon == true { // checked everyframe that hero jumped
        jumpingTimer = NSTimer.scheduledTimerWithTimeInterval(3, target: self, selector: "changeJump", userInfo: nil, repeats: true) // changing jump status
    }
}

how should i update my code to make the villain jump only once in three seconds,thanks in advance



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire