Latest 0.2.1
Homepage https://github.com/KyleGoslan/SKTimer
License MIT
Platforms ios 8.0, requires ARC
Authors

CI Status
Version
License
Platform
[CocoaPods]()

Requirements

Designed to be used in a SpriteKit project.

Usage

Create an instance of an SKTimer object

let timer = SKTimer()

Call the start(_:) method on your new timer passing in the current time from the scene. This is the currentTime parameter from your scenes update method. Usually you’ll want to create a property in your scene to hold this value so you’ll have access to it from outside your update method:

timer.start(currentTime)

In your scenes update method make sure you call the timers update(_:completion:) method passing in the current time. This is how the timer calculates its count:

timer.update(currentTime, timeUp: nil)

You can get the current time of the timer from it time property:

print(timer.time)

Example Scene

Here is very simple example scene that starts an SKTimer on a touch:

import SpriteKit
import SKTimer

class GameScene: SKScene {

    var currentTime = 0.0
    var timer = SKTimer()

    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        timer.start(currentTime)
    }

    override func update(currentTime: CFTimeInterval) {
        self.currentTime = currentTime

        if timer.on {
            print(timer.time)
            timer.update(currentTime, timeUp: nil)
        }
    }
}

Time Limits

You can set optional time limits for your timer and receive a callback when that limit is reached. Create a timer with a limit of 10 seconds like this:

var timer = SKTimer(limit: 10)

Multiplier

The default of the multiplier property is 1.0. You can increase or decrease this to speed up or slowdown the speed of the counter. E.g to create a timer that is twice as fast as real time:

var timer = SKTimer(multiplier: 2.0)

Installation

SKTimer is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "SKTimer"

Author

KyleGoslan

License

SKTimer is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "SKTimer",
    "version": "0.2.1",
    "summary": "Easy to use timer for SpriteKit games.",
    "description": "Easy to set up and use timer for SpriteKit games. A few extra options to set a time limit and get notified when it is reached as well as the ability to speed up and slow down the timer.",
    "homepage": "https://github.com/KyleGoslan/SKTimer",
    "license": "MIT",
    "authors": {
        "KyleGoslan": "[email protected]"
    },
    "source": {
        "git": "https://github.com/KyleGoslan/SKTimer.git",
        "tag": "0.2.1"
    },
    "social_media_url": "https://twitter.com/KyleGoslan",
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "source_files": "SKTimer"
}

Pin It on Pinterest

Share This