Hello guys,
I’m currently developping a shooter game and I’m facing a tricky problem : I’ve a player which fires colored bullets (BulletPlayer) who collide with enemies (Enemy) and destroy them. I’d add a colored FX (DamageFX) when a bullet hits an enemy but I cannot access to my bullet variables during the collision in order to get its color.
Here is my Enemy’s code, where I check collisions :
var bullet : Entity = collide("bulletPlayer", x, y);
if (bullet)
{
life--;
var damageFX : DamageFX = new DamageFX (bullet.bulletColor);
bullet = (bullet as BulletPlayer);
FP.world.add(damageFX);
// OR
// bullet.GenerateFX();
FP.world.remove(bullet);
}
Here is my BulletPlayer’s code :
override public function added():void
{
super.added();
img = new Image(IMG_BULLETPLAYER);
graphic = img;
setHitbox(img.width, img.height);
type = "bulletPlayer";
img.color = FP.choose(0x334D5C, 0x45B29D, 0xEFC94C, 0xE27A3F, 0xDF4949);
bulletColor = img.color;
}
public function GenerateFX():void
{
var damageFX : DamageFX = new DamageFX (bulletColor);
FP.world.add(damageFX);
}
Errors are: "Access of possibly undefined property bulletColor through a reference with static type net.flashpunk:Entity." and : "Call to a possibly undefined method generateFX through a reference with static type net.flashpunk:Entity."
I tried to figure this out for a long time, and still no solution just for having a FX with the same color than the bullet which hit the enemy … Do you have any ideas or suggestions ?
Thanks !