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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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