bkurtz13 Posted October 26, 2013 Share Posted October 26, 2013 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 More sharing options...
rich Posted October 26, 2013 Share Posted October 26, 2013 Hmm not really sure, I've asked the guy who kindly helped create the definitions file if he's got any ideas and will let you know. Link to comment Share on other sites More sharing options...
cdoty Posted October 27, 2013 Share Posted October 27, 2013 Unless the code was updated in between your post and mine, I see a Phaser.GAMES which is an Array and Phaser.Game, which is a class. My guess is with the case-insensitivity of javascript, Typescript treats Game and GAME as the same. Link to comment Share on other sites More sharing options...
cdoty Posted October 27, 2013 Share Posted October 27, 2013 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 More sharing options...
bkurtz13 Posted October 27, 2013 Author Share Posted October 27, 2013 Thanks Rich. I also tried using jsdocts to generate a new definitions file today with 1.1.1 and it had a bunch of issues. Link to comment Share on other sites More sharing options...
bkurtz13 Posted October 29, 2013 Author Share Posted October 29, 2013 @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 More sharing options...
ursuletzu Posted November 6, 2013 Share Posted November 6, 2013 Hey guys,it is now 6/11 and the typescript definition error is not fixed!!! Link to comment Share on other sites More sharing options...
rich Posted November 6, 2013 Share Posted November 6, 2013 It's open source for a reason. Mike and RestingCoder 2 Link to comment Share on other sites More sharing options...
Recommended Posts