kidos Posted August 26, 2014 Share Posted August 26, 2014 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 tweengame.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 playergame.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 More sharing options...
Chendler Posted August 26, 2014 Share Posted August 26, 2014 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 More sharing options...
ZoomBox Posted August 26, 2014 Share Posted August 26, 2014 Yep, collisions are not supposed to work with tweens.Collisions roughly only work with velocities. Link to comment Share on other sites More sharing options...
kidos Posted August 26, 2014 Author Share Posted August 26, 2014 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 More sharing options...
kidos Posted August 26, 2014 Author Share Posted August 26, 2014 I did a little hack to make it bounce,I added this to the collide callback function to get a bouncy effectif (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 More sharing options...
Recommended Posts