I'm using HaxeFlixel with this code to create a filter with makeGraphic()
instead of an image:
public function new()
{
trace('Shield created');
super();
makeGraphic(FlxG.width, FlxG.height, FlxColor.TRANSPARENT);
drawLine(30, 200, 300, 200, { thickness: 2, color: FlxColor.WHITE } );
var glowFilter = new GlowFilter(0x000000, 1, 10, 10, 3, 1);
spr2Filter = createFilterFrames(this, glowFilter);
tween2 = FlxTween.tween(glowFilter, { blurX: 10, blurY: 10 }, 1, { type: FlxTween.PINGPONG });
tween2.active = true;
}
override public function update(elapsed:Float):Void
{
updateFilter(this, spr2Filter);
super.update(elapsed);
}
function createFilterFrames(sprite:FlxSprite, filter:BitmapFilter)
{
var filterFrames = FlxFilterFrames.fromFrames(
sprite.frames, 50, 50, [filter]);
updateFilter(sprite, filterFrames);
return filterFrames;
}
function updateFilter(spr:FlxSprite, sprFilter:FlxFilterFrames)
{
sprFilter.applyToSprite(spr, false, true);
}
The problem is that it stops all animations. If I only apply the filter and comment the update()
function everything is ok, but then the glow is not animated.
What am I doing wrong?