Jump to content

Trouble with collission


Recommended Posts

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

HiThe reason that is happening is because you provide invalid arguments to your collide function:


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:


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.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:



Link to comment
Share on other sites


  • Recently Browsing   0 members

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