Porting from as3 to haxeflixel
-
I wanna port this to haxeflixel:
http://blog.oaxoa.com/2009/07/27/actionscript-3-as3-lightning-thunderbolt-electric-discharge-class/
Does someone know if I will have trouble with the filters? will they work in android/iOs?
any general tips of what to do or not to do?
-
@aschab
Following my idea I did the following code:package;
import flash.filters.GlowFilter;
import flixel.tweens.FlxTween;
import flixel.graphics.frames.FlxFilterFrames;
import flash.filters.BitmapFilter;import flixel.FlxG;
import flixel.FlxSprite;
import flixel.util.FlxColor;
import flixel.math.FlxPoint;
using flixel.util.FlxSpriteUtil;class Shield extends FlxSprite
{
private var spr2Filter:FlxFilterFrames;
private var tween2: FlxTween;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); }
}
inspired on http://haxeflixel.com/demos/FlxSpriteFilters/Now my problem is in update when I run updateFilter(this, spr2Filter); all updates seem to stop. What am I missing? what im doing wrong?
-
I'm new to HaxeFlixel, and Flixel for that matter, but I always specify the functions return type. This may not be the reason for your problem though.
function createFilterFrames(sprite:FlxSprite, filter:BitmapFilter):FlxFilterFrames { var filterFrames = FlxFilterFrames.fromFrames( sprite.frames, 50, 50, [filter]); updateFilter(sprite, filterFrames); return filterFrames; } function updateFilter(spr:FlxSprite, sprFilter:FlxFilterFrames):Void { sprFilter.applyToSprite(spr, false, true); }
I checked out that effect. It's really cool. Good luck!
-
Nice catch, actually that code is mostly copied from the demos, they had it like that. But didnt solve it.
So far I can say that I'm doing something wrong on the filter, or maybe you can't put filters on drawed stuff (can someone confirm this)
I did a simple update with:
fill(FlxColor.TRANSPARENT);
drawLine(30, cy++, 300, 200, { thickness: 2, color: FlxColor.WHITE } );
Works like a charm, I get a moving line.BUT when I activate the filter, nromal, without any updates, the line never updates and all animations stop. So something is broken in the update of my filtered sprite.
I only want to achieve an animated glowing of a drawed line (animated or static, doesnt matter). If anyone can point me in the right direction would be appreciated