Shana Posted March 6, 2014 Share Posted March 6, 2014 Hi guys, it's me again \o . So, I have another problem, i worked on it for 3-4 hours yesterday, and I give up... So, my problem is simply : I can't add state, or simply call it. So, my app.ts (Yhea, I'm following the tutorial) :/// <reference path="phaser.d.ts" />/// <reference path="Boot.ts" />/// <reference path="Preloader.ts" />/// <reference path="MainMenu.ts" />module Castlevania { export class MainGame { game: Phaser.Game; constructor() { this.game = new Phaser.Game(800, 600, Phaser.AUTO, 'content', { preload: this.preload, create: this.create }); } preload() { } create() { this.game.state.add("boot", Castlevania.Boot, true); console.log(this.game.state); } }}window.onload = () => { var game = new Castlevania.MainGame();};My Boot.ts :/// <reference path="phaser.d.ts" />module Castlevania { export class Boot extends Phaser.State { constructor() { super(); } preload() { console.log("IT WORKS !!!"); //this.game.load.image('preloadBar', 'assets/loader.png'); } create() { console.log("IT WORKS!!!"); } update() { } }}(Yhea, I tried to put a constructor, but it doesn't work \o ) So, in my log of state, I have :Phaser.StateManager - No state found with the key: boot phaser.js:9225Phaser.StateManager_created: true_pendingState: ObjectcallbackContext: Objectcurrent: "default"game: Phaser.GameonCreateCallback: function () {onInitCallback: function () {onLoadRenderCallback: nullonLoadUpdateCallback: nullonPausedCallback: nullonPreRenderCallback: nullonPreloadCallback: function () {onRenderCallback: nullonShutDownCallback: function () {onUpdateCallback: nullstates: Objectboot: undefineddefault: Object__proto__: Object__proto__: Object So, now I'm lost. I tried everything, but nothing works...Can u help me ? Thanks . EDIT : When I try this : console.log("TEST");var b = new Castlevania.Boot();console.log("TEST2");console.log(;console.log("TEST3");this.game.state.add("boot", b, true);console.log(this.game.state);I have :TEST app.ts:21Uncaught TypeError: undefined is not a function Link to comment Share on other sites More sharing options...
cheshirepuss42 Posted March 6, 2014 Share Posted March 6, 2014 I'm not sure why your code fails, but I'll show you what works for me: /states/Boot.tsmodule WM.States { export class Boot extends Phaser.State { constructor() { super(); } render() { } create() { this.game.state.start("preload", true, false); } update() { } }}/states/Preload.tsmodule WM.States { export class Preload extends Phaser.State { constructor() { super(); } preload() { } render() { } update() { } }}/Game.tsmodule WM { export class Main extends Phaser.Game { constructor() { super(800, 600, Phaser.CANVAS, "bla"); this.state.add("boot", States.Boot); this.state.add("preload", States.Preload); this.state.start("boot"); } }}var wm:WM.Main;window.onload = () => { wm = new WM.Main(); };In addition to that i have a _reference.ts in the root which contains something like: /_reference.ts/// <reference path="states/boot.ts" />/// <reference path="states/preload.ts" />But this might be specific to how i compile typescript. This allows me to make sure that everything gets referenced. Just place the files you call in the right order and if needed you place a reference like/// <reference path="../_reference.ts" />above the class where you use other classes.I'll write a tutorial about my approach as soon as I have everything working as needed (waiting for Phaser 2.0 and it's typescript definitions).Hope this helps you. Link to comment Share on other sites More sharing options...
Shana Posted March 6, 2014 Author Share Posted March 6, 2014 I'll try, thank you. I'll edit this message to say if it works or not. EDIT : It doesn't work, even if I copy/paste your code... I'm gonna kill myself... Link to comment Share on other sites More sharing options...
cheshirepuss42 Posted March 6, 2014 Share Posted March 6, 2014 Can you be more specific in what you did, and where it fails? Link to comment Share on other sites More sharing options...
Shana Posted March 6, 2014 Author Share Posted March 6, 2014 Yhea, I'm simply following the tutorial (TypeScript & Phaser so), and I'm in the second part. So I did the same as the tutorial, with the modules and the states.Well, when I do "this.game.state.add("thing", Castlevania.Boot, false);" (So, the same line), I have this error :Phaser.StateManager - No state found with the key: boot phaser.js:9225Phaser.StateManager_created: true_pendingState: ObjectcallbackContext: Objectcurrent: "default"game: Phaser.GameonCreateCallback: function () {onInitCallback: function () {onLoadRenderCallback: nullonLoadUpdateCallback: nullonPausedCallback: nullonPreRenderCallback: nullonPreloadCallback: function () {onRenderCallback: nullonShutDownCallback: function () {onUpdateCallback: nullstates: Objectboot: undefineddefault: Object__proto__: Object__proto__: ObjectSo I've tried to instanciate this class :console.log("TEST");var b = new Castlevania.Boot();console.log("TEST2");console.log(;console.log("TEST3");this.game.state.add("boot", b, true);console.log(this.game.state);And it fails at "var b = new Castlevania.Boot();", and it gives me that error :TEST app.ts:21Uncaught TypeError: undefined is not a function I tried everything, but nothing works, even if I copy and paste the same code as above. Link to comment Share on other sites More sharing options...
cheshirepuss42 Posted March 7, 2014 Share Posted March 7, 2014 Sorry, I can't help you further, maybe someone else? Link to comment Share on other sites More sharing options...
Shana Posted March 7, 2014 Author Share Posted March 7, 2014 I'm gonna use again Haxe & Flixel I think.Thank you anyway Link to comment Share on other sites More sharing options...
clark Posted March 10, 2014 Share Posted March 10, 2014 I cannot see where you are starting the state. CheshirePuss42's code looks good to me. It appears you are trying to create States and call them by constructor instead of his example?this.state.start("boot"); Link to comment Share on other sites More sharing options...
Luis Fonseca Posted April 24, 2014 Share Posted April 24, 2014 I'm going mad with this too... I followed pretty much the Typescript part 2 tutorial letter by letter and I'm getting the same problem as the user above: Phaser.StateManager - No state found with the key: Boot Link to comment Share on other sites More sharing options...
sarzhevski Posted November 28, 2014 Share Posted November 28, 2014 From my point of view problem is not in "Phaser". You created a new typescript file Boot.ts. It means, you split your module across files. In this case just make sure all of the compiled code gets loaded. Uncaught TypeError: undefined is not a function It looks like you forget about it. <script src="Boot.js" type="text/javascript" />. You can read about it here. Hope it will helps somebody : ) Link to comment Share on other sites More sharing options...
jpdev Posted November 28, 2014 Share Posted November 28, 2014 Not very likely, that someone who had this problem in april is still stuck on it But you are most likely correct. It happens to me all the time when I add new files to my project.. I define a new class in the file, I add the "reference" statement to the TS-file where I want to use it.. and then wonder why the game crashes in the browser. after a bit of wondering I add the resulting .js from the new file do my debug.index.html and everything works fine. Link to comment Share on other sites More sharing options...
Recommended Posts