I want to create this effect, that the score is changing with a delay between every number, like the score on the game over screen in Flappy Bird.
In this example, it should start counting when I touch the screen.
import SpriteKit
class GameScene: SKScene, SKPhysicsContactDelegate {
// Global declaration of objects
var scoreLabel = SKLabelNode()
var score:Int = 15
override func didMoveToView(view: SKView) {
/* Setup your scene here */
scoreLabel = SKLabelNode(fontNamed: "RubberBiscuitBold")
scoreLabel.fontSize = 50
scoreLabel.fontColor = SKColor.blackColor()
scoreLabel.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame))
scoreLabel.zPosition = 1000
self.addChild(scoreLabel)
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
/* Called when a touch begins */
for var i = 0; i <= score; i++ {
scoreLabel.runAction(SKAction.waitForDuration(1))
scoreLabel.text = "\(i)"
print("\(i)")}
}