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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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