oliversb Posted May 10, 2014 Share Posted May 10, 2014 TypeError: texture is undefined phaser.js:1717"Phaser.StateManager - No state found with the key: pmSCENEScene" phaser.js:14293TypeError: _this.boot is not a function How can I use this information to fix bugs in my Javascript code? Is there a particular system I should be using for debugging. I am trying to add a sprite to my game and it says 'texture is undefined'. I added a state as shown in the example and then started it and I've followed the code here https://github.com/photonstorm/phaser/wiki/Phaser-General-Documentation-:-States. I don't know where the _this.boot comes from. So please help. Thanks Link to comment Share on other sites More sharing options...
stasuss Posted May 10, 2014 Share Posted May 10, 2014 full code please Link to comment Share on other sites More sharing options...
oliversb Posted May 10, 2014 Author Share Posted May 10, 2014 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="content-type" content="text/html;charset=utf-8" /><title>as</title><script src="src/prototype.js" type="text/javascript"></script><script src="src/phaser.js" type="text/javascript"></script><script src="src/PowerModeEngine.js" type="text/javascript"></script><style type="text/css">body {background-color: #3B3B3B;font-family: arial, verdana, sans-serif;font-size: 12px;}#canvas{background-color: #FFFFFF;display: block;margin: 0 auto;}</style><script type="text/javascript">//End Of Variablesfunction init() {game = Phaser.Game(640, 480, Phaser.AUTO, 'game');game.state.add('pmSCENEScene', game.pmSCENEScene);game.state.start('pmSCENEScene');}function pmOBJECTObject(x, y, sprite) {//pmOBJECTObjectPowerModeObject.call(this, game, x ,y);function theConstructor () {//pmOBJECTObjectConstructor}}pmOBJECTObject.prototype = Object.create(PowerModeObject.prototype);pmOBJECTObject.prototype.constructor = pmOBJECTObject();pmSCENEScene = function(game) { };pmSCENEScene.prototype = {create: function() {addObject(new pmOBJECTObject(game, 85, 402));executeConstructors();},preload: function() {}}pmOBJECTObject.prototype.pmDestroy2 = function() {scene.removeObject(this);}//End Of PowerMode Functions</script></head><body onload='init()'></body></html> Link to comment Share on other sites More sharing options...
oliversb Posted May 10, 2014 Author Share Posted May 10, 2014 /* This script was created by Oliver Scott-Brown for use with the game development software, PowerMode.This script functions as the engine for PowerMode generated codeIf this script is distributed to the public, it must legally be used ONLY with PowerMode compiled web appshttp://www.powermodegames.comCopyright © 2014 Oliver Scott-Brown (check http://legal.powermodegames.com for legal details)*/ // declare variablesvar game;// functions to power the engine (excluding classes)function executeConstructors() { for (var i = 0; i < game.stage.children.length; i ++) { game.stage.children.theConstructor = function() {} game.stage.children.theConstructor(); }}function addObject(obj) { game.add.existing(obj); obj.animations.add('go'); obj.animations.play('go', 1, true);}function loadSpriteSheet(name) { game.load.spritesheet(name, 'media/' + name + '.json');}//classes that are built-in to the PowerMode enginevar PowerModeObject = function(game, x, y) { Phaser.Sprite.call(this, game, x, y);}PowerModeObject.prototype = Object.create(Phaser.Sprite.prototype);PowerModeObject.prototype.constructor = PowerModeObject; Link to comment Share on other sites More sharing options...
oliversb Posted May 10, 2014 Author Share Posted May 10, 2014 full code pleaseThanks Link to comment Share on other sites More sharing options...
stasuss Posted May 10, 2014 Share Posted May 10, 2014 game.state.add('pmSCENEScene', game.pmSCENEScene);try using this:game.state.add('pmSCENEScene', pmSCENEScene);this should solve the error "Phaser.StateManager - No state found with the key: pmSCENEScene" phaser.js:14293"this is because 'game.pmSCENEScene' is not defined. 'pmSCENEScene' defined in the scope of the 'Init' function, but not in the 'game' object. don't see '_this.boot' either. is this the whole source? try fixing the first error. may be the second will disappear. Link to comment Share on other sites More sharing options...
oliversb Posted May 10, 2014 Author Share Posted May 10, 2014 game.state.add('pmSCENEScene', game.pmSCENEScene);try using this:game.state.add('pmSCENEScene', pmSCENEScene);this should solve the error "Phaser.StateManager - No state found with the key: pmSCENEScene" phaser.js:14293"this is because 'game.pmSCENEScene' is not defined. 'pmSCENEScene' defined in the scope of the 'Init' function, but not in the 'game' object. don't see '_this.boot' either. is this the whole source? try fixing the first error. may be the second will disappear. I have changed this and I am still having problems This is what Firefox says in the console: TypeError: texture is undefined phaser.js:1717ReferenceError: pmSCENEScene is not defined index.html:30TypeError: _this.boot is not a function Thanks Link to comment Share on other sites More sharing options...
Sunburned Goose Posted May 10, 2014 Share Posted May 10, 2014 Can you place a 'debugger;' statement before line 30 to see if the pmSCENEScene exists? Link to comment Share on other sites More sharing options...
jpdev Posted May 10, 2014 Share Posted May 10, 2014 hi oliversb, The easiest way someone can check your code is if you put it up on the web, where it can directly be run.(Including the assets (or some demo assets) that are loaded.) Greetings,JP Link to comment Share on other sites More sharing options...
oliversb Posted May 10, 2014 Author Share Posted May 10, 2014 https://www.dropbox.com/sh/sfq9yltugecvzc1/AABEm5C4gktiFPBOb9J8qPMLa Thanks Link to comment Share on other sites More sharing options...
jpdev Posted May 11, 2014 Share Posted May 11, 2014 Figured out the first problem. The definition of pmSCENEScene does not work. You need:function pmSCENEScene(game) {};but right now you have:pmSCENEScene = function(game) { };(That's just not the way to define a function, or in this case a constructor.) This does not solve all problems, the game still won't start up. Link to comment Share on other sites More sharing options...
jpdev Posted May 11, 2014 Share Posted May 11, 2014 woah.. that took me some time.. you forgot the NEW in the first phaser line... game = new Phaser.Game(640, 480, Phaser.AUTO, 'game'); oliversb 1 Link to comment Share on other sites More sharing options...
oliversb Posted May 11, 2014 Author Share Posted May 11, 2014 Terribly sorry for the hassle. Thanks a ton. I will sort this out. Link to comment Share on other sites More sharing options...
jpdev Posted May 11, 2014 Share Posted May 11, 2014 Here is the fixed file. It still crashes, but only because you powermode object isn't really a sprite.. or something like that.(Not a state problem anymore ) Fixes: "new", prototype fixes (more then the one posted above) I have the strong feeling the wiki-tutorial is wrong at that point.(how the prototype is setup. - From my understanding that's just not how it works.)<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="content-type" content="text/html;charset=utf-8" /><title>as</title><script src="src/prototype.js" type="text/javascript"></script><script src="src/phaser.js" type="text/javascript"></script><script src="src/PowerModeEngine.js" type="text/javascript"></script><style type="text/css">body {background-color: #3B3B3B;font-family: arial, verdana, sans-serif;font-size: 12px;}#canvas{background-color: #FFFFFF;display: block;margin: 0 auto;}</style><script type="text/javascript">//End Of Variablesfunction init() {game = new Phaser.Game(640, 480, Phaser.AUTO, 'game');game.state.add('pmSCENEScene', pmSCENEScene);game.state.start('pmSCENEScene');}function pmOBJECTObject(x, y, sprite) {//pmOBJECTObjectPowerModeObject.call(this, game, x ,y);function theConstructor () {//pmOBJECTObjectConstructor}}pmOBJECTObject.prototype = Object.create(PowerModeObject.prototype);pmOBJECTObject.prototype.constructor = pmOBJECTObject();function pmSCENEScene(game) { }pmSCENEScene.prototype.create = function() {addObject(new pmOBJECTObject(game, 146, 372));executeConstructors();};pmSCENEScene.prototype.preload = function() {};pmOBJECTObject.prototype.pmDestroy2 = function() {scene.removeObject(this);};//End Of PowerMode Functions</script></head><body onload='init()'></body></html> Link to comment Share on other sites More sharing options...
oliversb Posted May 26, 2014 Author Share Posted May 26, 2014 Thanks for the help. Link to comment Share on other sites More sharing options...
Recommended Posts