Jump to content

Particle emitter and sprite collision callback not working.


prateek.pradeep
 Share

Recommended Posts

I am using particle emitter to generate particle and i want a call back when each of the particle collide with my body.

Here is the NOT WORKING code:

 

 

var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render:render });

var leftEmitter;
var rightEmitter;
var ball;
var score_label;
function preload() {

    game.load.image('sky', 'assets/skies/cavern2.png');
    game.load.spritesheet('balls', 'assets/sprites/balls.png', 17, 17);

}

function create() {

    ball = game.add.image(300,300 , 'balls',0);
    ball.scale.setTo(15,15);
    game.physics.enable(ball, Phaser.Physics.ARCADE);

    leftEmitter = game.add.emitter(50, game.world.centerY - 200);
    leftEmitter.setXSpeed(100, 200);
    leftEmitter.setYSpeed(-50, 50);
    leftEmitter.enableBody = true;
    leftEmitter.physicsBodyType  = Phaser.Physics.ARCADE;
    leftEmitter.makeParticles('balls', [0,1,2], 1, true, true);

    // explode, lifespan, frequency, quantity
    leftEmitter.start(false, 5000, 100);


}

function update() {

    game.physics.arcade.collide(ball, leftEmitter, change, null, this);

}

function change(a, b ) {
   //Not getting any  callback

}
 

Link to comment
Share on other sites

maybe (a shot into the blue)  you need to create particles before adding a physics body so all particles get this physics body??

 

in this example it's working without enableBody or bodyType

 http://examples.phaser.io/_site/view_full.html?d=particles&f=when+particles+collide.js&t=when%20particles%20collide

 

Your guess did not worked.

I modified the same example as you mentioned and landed up to this problem.

Link to comment
Share on other sites

Not sure what you tried to do to the poor emitter.. this works:

(I just removed the rightEmitter from the example and added a physics enabled ball...)

var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });var leftEmitter;var ball;function preload() {    game.load.spritesheet('balls', 'balls.png', 17, 17);}function create() {    leftEmitter = game.add.emitter(50, game.world.centerY - 200);    leftEmitter.bounce.setTo(0.5, 0.5);    leftEmitter.setXSpeed(100, 200);    leftEmitter.setYSpeed(-50, 50);    leftEmitter.makeParticles('balls', 0, 250, 1, true);    ball = game.add.sprite(100,100, "balls", 2);    ball.scale.x = 5;    ball.scale.y = 5;    game.physics.enable(ball, Phaser.Physics.ARCADE);    leftEmitter.start(false, 5000, 20);}function update() {    game.physics.arcade.collide(ball, leftEmitter , change, null, this);}function change(a,  {    a.frame = 3;    b.frame = 3;}
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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