Jump to content

[HELP] Group collider detection


bluecake
 Share

Recommended Posts

 

Hello,

Today I started with Phaser, I worked a lot at school with when I had free time. But I have a problem I can't delete an item in my group when my character makes a collision an item belonging to the group.

make my group: (in create function)

 game.physics.startSystem(Phaser.Physics.ARCADE);

 game.physics.enable(character, Phaser.Physics.ARCADE);
 game.physics.enable(enemygroup, Phaser.Physics.ARCADE);

 enemygroup = game.add.group();
    
 for(var i=0; i<10 ;i++)
     {
            var s = enemygroup.create(game.world.randomX, game.world.randomY, 'monster');
            s.frame = 3;
            s.animations.add('enemymove', [2,3,4], 10, true);
            s.play('enemymove');
            game.physics.enable(s, Phaser.Physics.ARCADE);
     }

 

for detect collider:(in update function)

 game.physics.arcade.collide(character, enemygroup, function(){
                 enemygroup.remove(this);
            }); 



/*OTHER WAY I HAVE TRY*/
 for(var i = 0; i < enemygroup.length; i++)
 {
     if(game.physics.arcade.collide(character, enemygroup))
     {
          enemygroup.remove(enemygroup[i]);
     }
 }

 

 

Thanks you for help !

good development at all and sorry for my bad english (i'm french).

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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