Using ImpactJS: How to set a publicly available variable
- by Dave Voyles
I'm trying to get an entity (a bullet, a grenade, and an explosive) from my player player. Specifically, I want the shootingRate of my bullet (how frequently it can be fired).
How can I do this without having to call getEntityByType each time I fire this projectile? There has got to be a cleaner way from what I'm doing right now....
// Shooting
var isShooting = ig.input.state('shoot');
if (isShooting && this.lastShootTimer.delta() > 0) {
switch (this.activeWeapon)
{
case("EntityBullet"):
ig.game.spawnEntity(this.activeWeapon, this.pos.x, this.pos.y - 10);
var equipedWeap = ig.game.getEntitiesByType(EntityBullet);
this.lastShootTimer.set(equippedWeap.shootingRate);
console.log(equipedWeap.shootingRate);
break;
case("EntityGrenade"):
ig.game.spawnEntity(this.activeWeapon, this.pos.x, this.pos.y +5);
var equipedWeap = ig.game.getEntitiesByType(EntityGrenade);
this.lastShootTimer.set(equipedWeap.shootingRate);
console.log(EquipedWeap.shootingRate);
break;
case("EntityExplosiveBomb"):
ig.game.spawnEntity(this.activeWeapon, this.pos.x, this.pos.y +5 );
var equipedWeap = ig.game.getEntitiesByType(EntityExplosiveBomb)[0];
this.lastShootTimer.set(equipedWeap.shootingRate);
console.log(equipedWeap.shootingRate);
break;
}
}