Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by DaveVoyles

'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 equippedWeap = ig.game.getEntitiesByType(EntityBullet);
this.lastShootTimer.set(equippedWeap.shootingRate);
console.log(equippedWeap.shootingRate);
break;
case("EntityGrenade"):
ig.game.spawnEntity(this.activeWeapon, this.pos.x, this.pos.y +5);
var equippedWeap = ig.game.getEntitiesByType(EntityGrenade);
this.lastShootTimer.set(equippedWeap.shootingRate);
console.log(EquippedWeap.shootingRate);
break;
case("EntityExplosiveBomb"):
ig.game.spawnEntity(this.activeWeapon, this.pos.x, this.pos.y +5 );
var equippedWeap = ig.game.getEntitiesByType(EntityExplosiveBomb)[0];
this.lastShootTimer.set(equippedWeap.shootingRate);
console.log(equippedWeap.shootingRate);
break;
}
}

1 decade ago by Graphikos

ig.game.spawnEntity returns the spawned entity so you can just put it in a var.

var equippedWeap = ig.game.spawnEntity(this.activeWeapon, this.pos.x, this.pos.y +5);

1 decade ago by DaveVoyles

Worked like a charm, thank you!
Page 1 of 1
« first « previous next › last »