Lerp in flambe

32 views
Skip to first unread message

mgr...@teravisiongames.com

unread,
Nov 9, 2015, 9:42:28 AM11/9/15
to Flambe
Hi all!!, is there any function in the flambe framework that simulates the Unity's Lerp function?

Best Regards

Message has been deleted

Martin Parent

unread,
Nov 9, 2015, 10:49:14 AM11/9/15
to Flambe, mgr...@teravisiongames.com
No but you can create your own Math Utils class and add the lerp function to it:

public static function lerp(start:Float, end:Float, percent:Float):Float
{
   
if (start == end)
   
{
       
return start;
   
}
   
return (end - start) * percent + start;
}

Marcos Grillo

unread,
Nov 9, 2015, 1:19:00 PM11/9/15
to Martin Parent, Flambe
Thanks!, I used a slighter different implementation

public static function lerp(start:Float, end:Float, percent:Float):Float
{
    return start + (percent*(end - start));
}
--
Ing. Marcos Grillo

Mark Knol

unread,
Nov 9, 2015, 4:50:27 PM11/9/15
to Flambe, mpa...@bkom.com, mgr...@teravisiongames.com
If you want to take deltatime in account, you might want to use this:

    inline public static function lerpMoveTo(from:Float, to:Float, deltaTime:Float, duration:Float):Float {
      return (to - from) * (1 - Math.pow(0.01, deltaTime / duration));
    }

With this you can use it like this:

    override public function onUpdate(dt:Float) {
      var sprite = owner.get(Sprite);
      sprite.x._ += lerpMoveTo(sprite.x._, targetX, dt, 4);
      sprite.y._ += lerpMoveTo(sprite.y._, targetY, dt, 4);
    }

Enjoy your day!

Marcos Grillo

unread,
Nov 9, 2015, 5:23:46 PM11/9/15
to Mark Knol, Flambe, Martin Parent
That looks nice, thanks Mark!!!
--
Ing. Marcos Grillo
Reply all
Reply to author
Forward
0 new messages