Search the Community
Showing results for tags 'initialize'.
-
Hi. I have a big problem with my Phaser project. I use Phaser + Typescript. I use this tutorial: http://blog.lessmilk.com/how-to-make-flappy-bird-in-html5-1/ If I use the following code, I get this error: "Uncaught TypeError: Cannot set property 'gravity' of null" class FlappyBirdsGame { game: Phaser.Game; bird; constructor(renderDiv: String) { this.game = new Phaser.Game(400, 490, Phaser.AUTO, renderDiv, { preload: this.preload, create: this.create, update: this.update }); this.game.state.add('main', this); } preload() { this.game.stage.backgroundColor = '#71c5cf'; this.game.load.image('bird', 'assets/bird.png'); } create() { this.bird = this.game.add.sprite(100, 245, 'bird'); this.bird.body.gravity = 1000; var spaceKey = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); spaceKey.onDown.add(this.jump, this); } update() { if (this.bird.inWorld == false) { this.restartGame(); } } jump() { this.bird.body.velocity.y = -350; } restartGame() { this.game.state.start('main'); }}window.onload = () => { var game = new FlappyBirdsGame('content');}What is the problem? If I run this code, the "bird" is displayed. You can see the source also on git: https://github.com/ppfeiler/FlappyBirdClon Thank you
- 5 replies
-
- phaser
- typescript
-
(and 3 more)
Tagged with: