projectiles = new FlxTypedGroup<Projectile>(maxProjectiles);
var projectile:Projectile;
for (i in 0...maxProjectiles) {
projectile = new Projectile();
projectiles.add(projectile);
projectile.kill();
}
add(projectiles);
private function onShoot():Void
{
isShooting = true;
var projectile = projectiles.recycle();
projectile.x = sprite.x + (sprite.width - projectile.width) / 2;
projectile.y = sprite.y - projectile.height / 2;
projectile.fire();
projectiles.forEachAlive(function(currentProjectile:Projectile) {
if (currentProjectile.height == 10) {
isShooting = false;
currentProjectile.kill();
}
});
}
package;
import flixel.FlxSprite;
import flixel.util.FlxTimer;
class Projectile extends FlxSprite
{
private var speed:Float = 0.2;
private var timer:FlxTimer;
public function new()
{
super();
timer = new FlxTimer();
makeGraphic(5, 1, 0xffff0000);
}
override public function update():Void
{
super.update();
height = timer.elapsedLoops;
scale.set(1, height);
}
public function fire():Void
{
timer.start(speed, 0);
}
}
private function onShoot():Void
{
isShooting = true;
var projectile = projectiles.recycle();
trace(projectile);
projectile.x = sprite.x + (sprite.width - projectile.width) / 2;
projectile.y = sprite.y - projectile.height / 2;
projectile.fire();
}
public function shootComplete(projectile:Projectile):Void
{
isShooting = false;
projectile.x = 0;
projectile.y = 0;
projectile.height = 1;
projectile.kill();
}
package;
import flixel.FlxSprite;
import flixel.util.FlxTimer;
import Player;
class Projectile extends FlxSprite
{
private var speed:Float = 0.01;
private var timer:FlxTimer;
private var player:Player;
public function new(player:Player)
{
super();
this.player = player;
timer = new FlxTimer();
makeGraphic(5, 1, 0xffff0000);
}
override public function update():Void
{
super.update();
height = timer.elapsedLoops;
scale.set(1, height);
if (timer.loopsLeft == 0) {
player.shootComplete(this);
}
}
public function fire():Void
{
timer.start(speed, 100);
}
}
How are you resetting the height? By calling something like
projectile.height = 0;
projectile.visible = false;
--
HaxeFlixel Development Community
See our github https://github.com/haxeflixel/ and our documentation http://haxeflixel.com/documentation/
---
You received this message because you are subscribed to a topic in the Google Groups "HaxeFlixel" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/haxeflixel/saUFTUxANrE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to haxeflixel+...@googlegroups.com.
Visit this group at https://groups.google.com/group/haxeflixel.
To view this discussion on the web visit https://groups.google.com/d/msgid/haxeflixel/3e824721-12eb-41e8-a171-99012a94decb%40googlegroups.com.