Skip to content
Gentilhomme edited this page Jul 26, 2016 · 3 revisions

Timer

Timers are simple clock that increments by 1 each frame. They help you to execute triggers at specific time or creating ... clock ^^.

Example in a Superpowers behavior

class gameBehavior extends Sup.Behavior {
    private timer : United.Timer;

    awake() {
        this.timer = new United.Timer();
    }

    update() {
        if(this.timer.walk(U.FPS * 2)) { // FPS * 2 equal 120 frames
            // Execute this block every two seconds
        }
        if(this.timer.elapsed(U.FPS * 160)) { 
            // Execute one time this block when 160 seconds have elapsed.
            this.timer.reset(); // The end of the round ? Restart the game :D
            // RestartGame();
        }
    }
}

Class methode

constructor(autoStart?: boolean = true) 
start() : void
stop() : void
reset() : void
getTick(interval: number) : number
walk(interval: number) : boolean
elapsed(elapsedFrame: number) : boolean

Timer are updated by the Engine.

update() : void
Clone this wiki locally