johntk86 Posted September 26, 2015 Share Posted September 26, 2015 I'm creating my first Phaser game as a chromecast receiver app, I'm having some trouble with my code. The code I have below works: class TNSeconds { game: Phaser.Game; constructor() { this.game = new Phaser.Game(window.innerWidth * window.devicePixelRatio -20, window.innerHeight * window.devicePixelRatio -20, Phaser.CANVAS, 'content', { preload: this.preload, create: this.create }); } preload() { this.game.load.image('BG', 'bg.png'); this.game.load.atlas("Atlas", "atlas.png", "atlas.json"); } create() { var background= this.game.add.sprite(this.game.world.centerX, this.game.world.centerY, 'BG'); logo.anchor.setTo(0.5, 0.5); this.game.add.sprite(320, 100, "Atlas", "dron1", this.game.world); } } window.onload = () => { var game = new TNSeconds(); }; However I'm following a tutorial and the example has the code laid out as so: class Game extends Phaser.Game { constructor() { // init game super(window.innerWidth * window.devicePixelRatio - 20, window.innerHeight * window.devicePixelRatio - 20, Phaser.CANVAS, 'content', State); } } class State extends Phaser.State { preload() { this.game.load.image('BG', 'bg.png'); this.game.load.atlas("Atlas", "atlas.png", "atlas.json"); } create() { this.add.image(0, 0, "BG"); this.add.sprite(320, 100, "Atlas", "dron1", this.world); } } window.onload = () => { var game = new Game(); }; The tutorials code seems cleaner and just for the sake of follwoing the tutorial I would like to implement my code similarly, the problem seems to be that the `State` class isn't initializing, could anybody shed some light on this for me. I'm aware the tutorial code is using `this.add.image` where I'm using `this.game.add.sprite` this is not an issue. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.