Jump to content

Difficulty with TypeScript in 1.1


bkurtz13
 Share

Recommended Posts

First of all, I've been following this project for months now, and I wanted to say thanks for all the hard work. I've been dying for 1.1 to release so I could try Phaser in TypeScript, and now that it's finally out I'm a little frustrated that I haven't been able to get the type definitions file to work correctly.

 

So far I've tried:

 

/// <reference path='phaser.d.ts'/>

 

as well as:

 

import Phaser = require('Phaser');

 

and can only get Phaser.GAME to pop up, for example, not Phaser.Game (var game = new Phaser.Game(blah blah...). It seems like there is a conflict in the .d.ts file between Phaser the class and Phaser the module. Has anyone got any advice or a working example? I was really looking forward to having code completion/Intellisense along with other static typing niceties.

Link to comment
Share on other sites

Actually there appears to be a problem in the d.ts file. The Game class define is set to accept a StateManager, but it should be State.

 

Here's my app.ts file

///<reference path='phaser.d.ts'/>import PhaserModule = Phaser;var game;function preload(){    game.load.image('mushroom', 'assets/mushroom2.png');}function create(){    //  This simply creates a sprite using the mushroom image we loaded above and positions it at 200 x 200    var test = game.add.sprite(200, 200, 'mushroom');}window.onload = () =>{	var state = new PhaserModule.State();	state.preload	= preload;	state.create	= create;	game = new PhaserModule.Game(800, 600, Phaser.AUTO, 'phaser-example', state, false, false);}

And my default.html file:

<!DOCTYPE html><html lang="en"><head>    <meta charset="utf-8" />    <title>TypeScript Phaser App</title>    <link rel="stylesheet" href="app.css" type="text/css" />    <script src="phaser.min.js"></script>    <script src="app.js"></script></head><body></body></html>
Link to comment
Share on other sites

@cdoty: I think my last post didn't show up until after you responded. At any rate, I finally got a chance to try out your suggestions. I changed in the Game constructor the StateManager to State like you mentioned and I was able to get the simple example you demonstrated to work correctly.

 

Now I can dig in a little more and try using some of the samples with TypeScript, so thanks!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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