Sign in to follow this  
bluecake

[HELP] Group collider detection

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.