Jump to content

Group out of bounds


mk12001
 Share

Recommended Posts

Hi,

 

I'd like to understand the group outOfBoundsKill function.

 

so I created a group, soldiers, in my create method:

 

soldiers = game.add.group();soldiers.enableBody = true;soldiers.physicsBodyType = Phaser.Physics.ARCADE;soldiers.setAll('outOfBoundsKill',true);soldiers.setAll('checkWorldBounds',true);createSoldiers();
 
And I created a separate function, createSoldiers() to create individual objects under that group.
 
function createsoldiers(){for (var ctr = 0; ctr < 4; ctr++)        {            var soldier = soldiers.create(game.world.randomX, 100, 'soldierSprite');            soldier.anchor.setTo(0.5, 0.5);            soldier.body.moves = false;        }}

For some reason, even if the soldiers are already out of bounds, the soldiers.setAll('outOfBoundsKill',true); doesn't kill it as checked from console.log("candies" + candies.countLiving());

 

I did something like the code below but I couldn't make the code to work due to an error that soldier isn't existing (not sure how to pass the object as an argument if it's in a group).

function checkCandies(){for (var ctr = 0; ctr < 4; ctr++){soldier.events.onOutOfBounds.add(destroySoldier, this);}}function destroyCandy(soldier){soldier.kill();}

In the invaders sample (http://phaser.io/examples/v2/games/invaders), there's a resetBullet function that isn't called. Not sure if it's automatically called by the system.

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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