Check out the code below. It creates and updates a buffer of Entity positions. Rendering is done by drawing same graphics from earliest position to current one. Assuming that graphics is an Image its alpha can be modified to make furthermost sprites almost invisible.
I guess this code could even be converted to be some smart Class that other motionblurred entites may derive from.
package
{
import net.flashpunk.*;
import net.flashpunk.graphics.*;
import net.flashpunk.tweens.misc.*;
import net.flashpunk.utils.*;
/**
* ...
* @author rostok
*/
public class MotionBlurred extends Entity
{
private var steps:uint = 5;
private var positions:Vector.<Number> = new Vector.<Number>;
public function MotionBlurred(x:Number=0, y:Number=0, graphic:Graphic=null)
{
this.x = x;
this.y = y;
this.graphic = graphic;
for (var i:int = 0; i < steps; i++) {
positions.push(x);
positions.push(y);
}
}
override public function update():void
{
positions.push(x);
positions.push(y);
if (Input.mousePressed) {
clearTweens();
var t:VarTween;
t = new VarTween();
t.tween(this, "x", Input.mouseX + world.camera.x, 0.5);
addTween(t, true);
t = new VarTween();
t.tween(this, "y", Input.mouseY + world.camera.y, 0.5);
addTween(t, true);
}
super.update();
}
override public function render():void
{
var lastX:Number = positions.shift();
var lastY:Number = positions.shift();
for (var i:int = 0; i < steps; i++) {
Image(graphic).alpha = i / steps;
Draw.graphic(graphic, FP.lerp(lastX, x, i / steps), FP.lerp(lastY, y, i / steps));
}
Image(graphic).alpha = 1;
super.render();
}
}
}
init:
var e:Entity = FP.world.add(new MotionBlurred(0, 0, new Image(FP.getBitmap(embedClass))));