Jump to content

How to make coins explode out of monster


kelvinblade
 Share

Recommended Posts

I am trying to make coins explode out of a monster when it is killed. the explode would be similar to this example: http://phaser.io/examples/v2/particles/diamond-burst

I also want the coins to be clicked individually similar to this example:http://phaser.io/examples/v2/groups/call-all-input

I am confused as to how to incorporate the two above examples together. Is emitting particles the way to go? I am also confused as to how to set each coin to have a different value depending on the monster.

Any help is appreciated.

 

Link to comment
Share on other sites

you could create a pool of sprites and only reset them when needed with a custom function that also sets some other variables..



coins = game.add.group();  // add a new group for fireballs
coins.createMultiple(500, 'coin', 0, false);  // create plenty of them hidden and out of the game world


on explode: 

 



function explode() {
        var coin = coins.getFirstExists(false); // get the first created fireball that no exists atm
        if (coin){
            coin.exists = true;  // come to existance !
            coin.lifespan=2500;  // remove the fireball after 2500 milliseconds - back to non-existance 
            coin.reset(monster.x, monster.y);
            game.physics.p2.enable(coin);
            coin.body.moveUp(800);
            coin.body.setCircle(10);
        }
   
}

Link to comment
Share on other sites

thanks!

 

ok my game is a tap based game.

 

after a few monsters die and the coins drop and some of them overlap, how can i make it so that one tap on an area picks them all up?

 

i currently have them as a group and i do :

 

this.coins.setAll('inputEnabled', true);
this.coins.callAll('events.onInputDown.add', 'events.onInputDown', this.removeCoin);
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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