agonya Posted June 14, 2017 Share Posted June 14, 2017 Hello my dear friends, I am trying to add animation to my bird object and I added for normal flying and It worked but when I try to add any other animation to same object it gives an error can you help me, I am adding my codes and the error message here, thanks! create: function() { this.bird = game.add.sprite(150, 200, 'bird'); this.bird.scale.setTo(0.1, 0.1); this.game.physics.arcade.enable(this.bird); this.bird.body.gravity.y = 1000; this.bird.animations.add('right', [0, 1], 5, true); this.bird.animations.add('dead', [2, 3], 5, true); this.bird.anchor.setTo(-0.2, 0.5); var spaceKey = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); spaceKey.onDown.add(this.fly, this); }, update: function() { this.game.physics.arcade.overlap(this.bird, this.blocks, this.killBird); }, fly: function() { if (this.bird.alive == false) return; this.bird.body.velocity.y = -325; var animation = game.add.tween(this.bird); animation.to({angle: -20}, 100); animation.start(); this.bird.animations.play('right'); }, killBird: function() { this.bird.animations.play('dead', 8, true); game.state.start('menu'); }, And I add the error message, and also my other problem is about pixel reformatting errors, how can I get rid of them, thanks. Link to comment Share on other sites More sharing options...
samme Posted June 14, 2017 Share Posted June 14, 2017 You need to pass a callback context in arcade.overlap. agonya 1 Link to comment Share on other sites More sharing options...
agonya Posted June 14, 2017 Author Share Posted June 14, 2017 15 minutes ago, samme said: You need to pass a callback context in arcade.overlap. Thank you, but how can I do it? My callback function is "this.killBird", Should it be like "this.killBird(this.bird)"? Sorry because I have been interested in Phaser for 20 days. @samme Link to comment Share on other sites More sharing options...
samme Posted June 14, 2017 Share Posted June 14, 2017 this.game.physics.arcade.overlap(this.bird, this.blocks, this.killBird, null, this); agonya 1 Link to comment Share on other sites More sharing options...
agonya Posted June 14, 2017 Author Share Posted June 14, 2017 @samme thanks a lot, you really helped me. Link to comment Share on other sites More sharing options...
Recommended Posts