alexanduh Posted April 30, 2018 Share Posted April 30, 2018 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 More sharing options...
samme Posted May 1, 2018 Share Posted May 1, 2018 Unfortunately the Arcade Physics colliders can't work with particles. But you could loop through the active particles and check for overlaps. Link to comment Share on other sites More sharing options...
alexanduh Posted May 2, 2018 Author Share Posted May 2, 2018 How would I go about that? I've narrowed it down to using a deathZone or set bounds for the emitter but I'm not sure how to run a callback when those events trigger. Link to comment Share on other sites More sharing options...
samme Posted May 3, 2018 Share Posted May 3, 2018 https://github.com/samme/phaser3-examples/blob/particles/public/src/game objects/particle emitter/death zone from arcade body.js Link to comment Share on other sites More sharing options...
alexanduh Posted May 7, 2018 Author Share Posted May 7, 2018 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 More sharing options...
samme Posted May 8, 2018 Share Posted May 8, 2018 var redColl = { contains: function (x, y) { var hit = sprite1.body.hitTest(x, y); if (hit) { /* ... */ } return hit; } }; Link to comment Share on other sites More sharing options...
Recommended Posts