I need to get each alive particle, add physics to it then attach a
collision callback to test if the particle is alive and coliiding with
my gameObject.
I have done something like this but its not working
gemEmitter.forEachAlive(function(particle,gemEmitter){
this.physics.add.existing(particle)
},this);
Then when i turn on the debugger, the particles have no body.
samme
December 18, 2022, 11:59am
2
Have you tried something like death zone from arcade body ?
@samme
I have, but it doesn’t seem to be what i want to do. I looked at every
example about particles but none showed how to get a single
emitted particle yet in the API it’s mentioned.
@samme
it worked. but now the bodies are displaced from their parent particles
Here is what i have so far.
let gem = this.add.particles('gem').setScale(.1);
let gemEmitter = gem.createEmitter({
x: this.scale.width / 0.18,
y: this.scale.height / .23,
frequency: 1000,
quantity: { min: 1, max: 2 },
alpha: 1,
tint: 0x00ff00,
followOffset: {
x: 0,
y: 0
},
emitCallback: (p)=>{
if(p.body) return;
var { width, height, halfWidth, halfHeight } = p.frame;
p.hasTransformComponent = true;
p.displayWidth = width;
p.displayHeight = height;
p.width = width;
p.height = height;
p.displayOriginX = halfHeight;
p.displayOriginY = halfHeight;
this.physics.add.existing(p);
p.body.moves = false;
},
emitCallbackScope:this
,
lifespan: 50000,
speed: { min: 500, max: 1000 },
maxVelocityX: 200,
maxVelocityY: 500,
blendMode: 'ADD'
});
this.player = this.physics.add.image(40, 40, 'ply').setOrigin(0).setScale(.08);
/** Overlap*/
this.physics.add.overlap(this.player, gemEmitter.alive);
There’s a large body moving randomly on the screen
samme
December 20, 2022, 2:31pm
7
I think you have to avoid scaling the particle manager.
You could scale the particles if you adjust the width, height, and origin values.