Hi,
I’m new to play canvas and I’m trying to make a bomberman game remake.
I’m trying to place a particle effect on screen whenever my bomb is about to explode.
Generally i would like to replace my bomb entity with an instantiation of an explosion entity.
The explosion particle effect i’m trying to make is a cross explosion similar to that of the original bombermanGames.
I somehow got an effect similar to this by using the particle_emitter.js the one referred to in the forums.
Now i’m trying to instantiate that explosion like how i instantiate bombs but the explosion doesn’t show up.
// In my inputs my character drops a bomb whenever space is pressed
// I created an entity called ExplosionParticles in the heirarchy and just disabled it
// I referenced that to clone new explosion particles
// when i attach a model on my empty entity and run it i see that the clone entity is actually being placed in the world.
// my problem is the particle effect is not showing unlike the bomb
// Is there anything specific i should know about this matter?
// Here’s the bomb script
pc.script.attribute(‘materials’, ‘asset’, [], {type: ‘material’} );
pc.script.create(‘Bomb’, function (context) {
// Creates a new Bomb instance
var Bomb = function (entity) {
this.entity = entity;
};
Bomb.prototype = {
// Called once after all resources are loaded and before the first update
initialize: function () {
this.entity.collision.on('collisionstart', this.onCollisionStart, this);
this.mat3 = context.assets.getAssetById(this.materials[2]).resource;
this.mat2 = context.assets.getAssetById(this.materials[1]).resource;
this.mat1 = context.assets.getAssetById(this.materials[0]).resource;
this.entity.model.model.meshInstances[0].material = this.mat1;
this.soundInstance = 0;
this.bombTimer = 5;
this.explode = context.root.findByName('ExplosionParticles');
},
// Called every frame, dt is time in seconds since last update
update: function (dt) {
this.bombTimer -= dt;
if(this.bombTimer >= 4 && this.bombTimer < 5){
this.entity.model.model.meshInstances[0].material = this.mat1;
}
else if(this.bombTimer >= 3 && this.bombTimer < 4){
this.entity.model.model.meshInstances[0].material = this.mat2;
}
else if(this.bombTimer >= 2 && this.bombTimer < 3){
this.entity.model.model.meshInstances[0].material = this.mat3;
}
else if(this.bombTimer >= 1.5 && this.bombTimer < 2){
if(this.soundInstance === 0){
this.entity.audiosource.play('BombExplosion');
this.soundInstance = 1;
var explosion = this.explosion.clone();
explosion.setPosition(this.entity.getPosition());
explosion.rigidbody.syncEntityToBody();
context.root.addChild(explosion);
}
}
/*else if(this.bombTimer >= 1 && this.bombTimer < 2){
this.entity.audiosource.play('Big Explosion');
}*/
else if(this.bombTimer <= 0){
this.entity.destroy();
}
},
onCollisionStart: function(result){
if(result.other.getName() === 'Ground'){
this.entity.rigidbody.linearVelocity = pc.Vec3.ZERO;
this.entity.rigidbody.angularVelocity = pc.Vec3.ZERO;
this.entity.rigidbody.angularFactor = pc.Vec3.ZERO;
}
else
return;
}
};
return Bomb;
});
Thanks in advance!