Jump to content

Help in start with Phaser & TypeScript


Recommended Posts


can someone help me in start with Phaser? I've read some tutorials, but Phaser still don't want to work.


I have 3 files. First is "index.ts":

/// <reference path="../phaser/phaser/Phaser/Game.ts" />(function () {    var myGame = new Phaser.Game(this, 'game', 800, 480, init, create, update, render);    function init() {        myGame.stage.scaleMode = Phaser.StageScaleMode.SHOW_ALL;    }    function create() {    }    function update() {    }    function render() {        myGame.stage.context.fillStyle = 'rgb(255,0,0)';        myGame.stage.context.font = 'bold 58px Arial';        myGame.stage.context.fillText(Phaser.VERSION + " works!", myGame.stage.centerX - 120, myGame.stage.centerY);    }})();

I compile this by command "tsc index.ts --target ES5" and I get the file "index.js".

I've one more file, "index.html":

<!DOCTYPE html><html><head>    <meta charset="utf-8" />    <title>heu heu</title>    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    <script src="index.js"></script></head><body></body></html>


That's all. When I open the html file, I see only white background. What's wrong with my code ?

Link to comment
Share on other sites

There are 2 things you can do:


1) Include the phaser.js file in your html file


2) If you want just one single JS output file then change the command-line you're using to this:


tsc index.ts --out game.js --target ES5

And it will compile the whole of Phaser + your index.ts file into game.js

Link to comment
Share on other sites


  • Recently Browsing   0 members

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