Jump to content

Collision between sprites and particles?


alexanduh
 Share

Recommended Posts

Hey all,

I'm trying to get a sprite to collide with a particle and run a function if they do - I currently have a particle emitter than emits particles and I'm not sure how to use the arcade physics collider to do this:

function create() {
    sprite1 = this.physics.add.sprite(700, 300, 'red');

    blue_trail = this.add.particles('blue_trail-particle').createEmitter({
        x: sprite2.x,
        y: sprite2.y,
        scale: { start: 0.02, end: 0.02 },
        blendMode: 'ADD',
        maxParticles: 0,
        lifespan: 50000
    });

    //confusion is here
    this.physics.add.collider(sprite1, blue_trail[what goes here?]);

 

Link to comment
Share on other sites

thanks so much, one last question: how can I run a function every time the "collision" occurs? here is the relevant code for reference:

function create() {
    var redColl = {
        contains: function (x, y)
        {
            //hi();
            return sprite1.body.hitTest(x, y);
        }
    };
    
    var blueColl = {
        contains: function (x, y)
        {
            //hi();
            return sprite2.body.hitTest(x, y);
        }
    };
    
    //blue trail
    blue_trail = this.add.particles('blue_trail-particle').createEmitter({
        x: sprite2.x,
        y: sprite2.y,
        scale: { start: 0.02, end: 0.02 },
        blendMode: 'ADD',
        maxParticles: 0,
        lifespan: 50000,
        deathZone: { type: 'onEnter', source: redColl }

    });

    //red trail
    red_trail = this.add.particles('red_trail-particle').createEmitter({
        x: sprite1.x,
        y: sprite1.y,
        scale: { start: 0.02, end: 0.02 },
        blendMode: 'ADD',
        maxParticles: 0,
        lifespan: 50000,
        deathZone: { type: 'onEnter', source: blueColl }
    });
}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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