callidus Posted August 27, 2014 Share Posted August 27, 2014 I have been trying to separate my code into states but no matter what I try the game comes up with a black screen, and an error saying "No state found with the key: playTest " . Here is my code: Thanks for any help this has been bothering me for a while *Note: each colour is a different file (index,load and playTest). Index:<!DOCTYPE html><html> <head><meta charset="utf-8" /><script src="phaser.js"></script><script src="load.js"></script><script src="playTest.js"></script></head> <body> <script> function create() { var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'game'); game.state.add("load",load);game.state.add("playTest",playTest);game.state.start("playTest");};</script></body</html> load: var load = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create}); function preload() {cursors = this.game.input.keyboard.createCursorKeys(); //allows keyboard inputthis.game.load.image("sky","assets/sky.png");} function create() {this.game.state.start("playTest")} play: var playTest = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update,}); function create() {this.game.add.image(0,0,"sky");this.game.add.text(16,16,"test");this.game.scale.pageAlignHorizontally = true; //centers canvasthis.game.scale.pageAlignVertically = true;this.game.scale.refresh(); } function update() { } Link to comment Share on other sites More sharing options...
Dumtard Posted August 27, 2014 Share Posted August 27, 2014 http://jsfiddle.net/e80atnum/var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example');var LoadState = function() {};var PlayState = function() {};LoadState.prototype = { preload: function() { this.load.image('sky', 'assets/sky.png'); }, create: function() { this.game.state.start('Play') }};PlayState.prototype = { create: function() { this.cursors = game.input.keyboard.createCursorKeys(); this.add.image(0, 0, 'sky'); this.add.text(16, 16, 'test'); this.scale.pageAlignHorizontally = true; //centers canvas this.scale.pageAlignVertically = true; this.scale.refresh(); }, update: function() { }};game.state.add('Load', LoadState, true );game.state.add('Play', PlayState); Link to comment Share on other sites More sharing options...
callidus Posted August 27, 2014 Author Share Posted August 27, 2014 Thanks to both of you, this solved my problem. Damn this community is fast I posted this like an hour ago lol. DELETE THIS ACC PLS 1 Link to comment Share on other sites More sharing options...
Recommended Posts