Jump to content

It can be used emitters with P2 physics?


AlexArroyoDuque
 Share

Recommended Posts

It is possible to define the collision system in P2 emitters. But I can not know how to use "setCollisionGroup" with the generated particles.

 

pice of code:

    this.emitterCoin = this.game.add.emitter(0, 0, 50);
    this.emitterCoin.enableBody = true;
    this.emitterCoin.physicsBodyType = Phaser.Physics.P2JS;
    this.emitterCoin.body.setCollisionGroup(this.coinCG);  // error
 
    this.emitterCoin.makeParticles('coin', [0], 100, true, true);
 
Any help with this?
Link to comment
Share on other sites

Hi alejandro,

the particles created by the emitter class are currently fixed to the Arcade Physics Engine. I believe it was a quick port from Rich so it can be included in the 2.0 release of Phaser. You cannot simply change the physics type without touching the original source or creating your own class either by inheriting Phaser.Particles.Arcade.Emitter or creating your very own Emitter Class. Look at the source from phaser.

Phaser.Particles.Arcade.Emitter.prototype.makeParticles = function (keys, frames, quantity, collide, collideWorldBounds) {    //[...] other code parts removed    particle = new Phaser.Sprite(this.game, 0, 0, rndKey, rndFrame);    this.game.physics.arcade.enable(particle, false);

Here you can see where the physics engine gets activated. There is no attribute 'physicsBodyType' involved in the particle creation (anyway, nice try).

 

How many coins do you want to create ? Maybe the easiest solution for you is to create a loop which creates each coin after another - including the correct physics behaviour and collision group. In other words: Try to forget the emitter, try to create ONE coin and if this works you should be able to create a hundred coins.

 

Have fun

Regards George

Link to comment
Share on other sites

i'd go with george's approach for now.. if enemy dies - get enemy.body.x and enemy.body.y and create as much coins as you need at the x and y coordinates...

@george the docs suggest that you CAN define another physics engine for the particles... maybe rich planned to implement this but didnt find the time yet..

Link to comment
Share on other sites

Well, we have to wait ... 

Sure later, Rich gives us something about particles in P2. 

Right now I have chosen to do a manual simulation. 

 

 

A piece of code. It works ok:

 


        for (var i = 0; i < obj.sprite.coins; i = i + 1) {

 

            var newCoin = theGame.emitterCoinGroup.getFirstExists(false);

            if (newCoin) {

                newCoin.reset(obj.x + utils.rangeRandom(-15, 15), obj.y - utils.rangeRandom(10, 50), 'coin');

                newCoin.body.velocity.x = utils.rangeRandom(- 50, 50);

                newCoin.body.data.gravityScale = 0.25;

                newCoin.anchor.setTo(0.5, 0.5);

                newCoin.body.setCollisionGroup(theGame.coinCG);

                newCoin.body.collides([theGame.playerCG, theGame.layerCG]);

                newCoin.lifespan = 20000;

                newCoin.body.mass = 0.01;

                newCoin.alpha = 0.8;

            }

        }

 

 

Thank you very much gamers.  :)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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