Sign in to follow this  
agonya

The second animation gives an error, help!

Recommended Posts

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.

Adsız.png

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.