Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Collide not working with tween


kidos
 Share

Recommended Posts

Hi,

I don't know what I'm doing wrong, I think it's a bug maybe.

 

I have an enemy which goes back and forth horizontally with a basic tween

game.add.tween(sprite).to({x: sprite.x-longWidth}, 1000, Phaser.Easing.Linear.None, true, 0, 9999, true) 

And I'de like to kill the enemy once it collides the player

game.physics.arcade.collide(player, enemy, this.killEnemy, null, this);

From some strange reason, it doesn't work if the enemy hit the player, but only if I move the player (with cursors) into the enemy (you can check the example below)

 

You can see the full code and example here (base code taken from lewster32 example):

http://jsfiddle.net/81duav6j/

 

Any Ideas?

Link to comment
Share on other sites

I think you mixed up 2 functions - collide and overlap.

game.add.tween(sprite).to({x: sprite.x-longWidth}, 1000, Phaser.Easing.Linear.None, true, 0, 9999, true);game.physics.arcade.collide(player, enemy);game.physics.arcade.overlap(player, enemy, this.killEnemy, null, this);
Link to comment
Share on other sites

Thanks, I have to use collide and not overlap.

The code was only to show the case, but in my real code the player can kill the enemy only if he above the anemy and if it doesn't it need to get bounce, which can achieved only collide. 

 

Any idea hot to make it work with bounce?

Link to comment
Share on other sites

I did a little hack to make it bounce,

I added this to the collide callback function to get a bouncy effect

if (player.body.facing == 3){    player.body.velocity.y = player.body.velocity.y * -1;}player.body.velocity.x = player.body.velocity.x * -1;
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...