thesystem_ Posted May 2, 2017 Share Posted May 2, 2017 I am trying to make a simple game where you are a ball and have to avoid objects. My code is available here: https://jsfiddle.net/skpvjoxb/ My problem is in line 69: I try to make collission between the player (sprite) and one of the enemies (enemy), but it doesn't work. Anyone can figure out how to make collission between enemy and sprite/player? Thank you so much Link to comment Share on other sites More sharing options...
samid737 Posted May 2, 2017 Share Posted May 2, 2017 HiThe reason that is happening is because you provide invalid arguments to your collide function: http://phaser.io/docs/2.4.4/Phaser.Physics.Arcade.html#collide In your case you can use groups to check for collision between your player and enemies. This way, you don't need to consider every enemy seperately: //create: enemies=game.add.group(); enemies.enableBody=true; var enemy = game.add.sprite(300, 0, 'enemy'); var enemy2 = game.add.sprite(75, 75, 'enemy'); var enemy3 = game.add.sprite(0, 300, 'enemy'); //game.physics.arcade.enable(enemy); //game.physics.arcade.enable(enemy2); //game.physics.arcade.enable(enemy3); enemies.addMultiple([enemy,enemy2,enemy3]); //update: game.physics.arcade.collide(sprite, enemies); //otherwise without groups: game.physics.arcade.collide(sprite, enemy); game.physics.arcade.collide(sprite, enemy2); game.physics.arcade.collide(sprite, enemy3); You can check sprite vs groups and even group vs groups: https://phaser.io/examples/v2/arcade-physics/group-vs-group https://phaser.io/examples/v2/arcade-physics/custom-sprite-vs-group Link to comment Share on other sites More sharing options...
thesystem_ Posted May 2, 2017 Author Share Posted May 2, 2017 Hey samid, Thank you so much, this works perfectly. I am really appreciative you took time to write an example of code and provide links. Hope you have a great day, once again thanks so much samid737 1 Link to comment Share on other sites More sharing options...
Recommended Posts