Jump to content

Newbie - Timer Class Trouble


impix
 Share

Recommended Posts

Hi,

 

I'm struggling to get phaser to display the fps of the game. Error is: Cannot read property 'game' of undefined. I've read around a bit: http://www.html5gamedevs.com/topic/7202-pausing-and-resuming-timer/ and looked at the manual but I've hit a bit of a wall. I've got a feeling I'm probably missing something incredibly obvious... 

 

Using latest version of typescript and running in latest version of node-webkit.

 

Code: 

/// <reference path="../definitions/phaser.d.ts" />class SimpleGame {    game: Phaser.Game;    fpsText: Phaser.Text;    fps: number;    timer: Phaser.Timer;    constructor() {        this.game = new Phaser.Game(800, 600, Phaser.AUTO, 'content', { preload: this.preload, create: this.create, update: this.update(), render: this.render() });    }    preload() {        console.log("preloaded");        this.game.load.image('logo', 'assets/logo.png');        this.timer = this.game.time.create(false);        this.timer.game.time.advancedTiming = true;    }    create() {        console.log("created");        this.fpsText = this.game.add.text(16, 16, 'fps: 0', { fontSize: '32px', fill: '#567' });    }    update(){    }    render(){        this.fpsText.text = 'fps: : ' + this.timer.game.time.fps;    }}window.onload = () => {    var game = new SimpleGame();};

Thanks for reading :)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...