aduros / flambe

Rapidly cook up games for HTML5, Flash, Android, and iOS.
https://github.com/aduros/flambe/wiki
MIT License
745 stars 118 forks source link

AnimatedFloat.watch() doesn't work as expected #357

Open macropp opened 8 years ago

macropp commented 8 years ago

Hi, I have an expandable panel which has a scissor applied to its Sprite. What I want to do is to animate the scissor height, for which I've created an AnimatedFloat and tried to create a watch function which will update the height of the scissor to animate the mask.

Code looks something like this:

var s:Sprite = // sprite from asset pack;
// s is then added to an Entity as a component
s.scissor = new Rectangle(0,0,100,20);

// creating animated float with the collapsed panel height
var animatedHeight:AnimatedFloat = new AnimatedFloat(20);
_heightListener = animatedHeight.watch(onHeightUpdate);

// then I try to animate the height
animatedHeight.animateTo(100, .15);

function onHeightUpdate(to:Float, from:Float):Void
{
    cast(/* get sprite */, Sprite).scissor.height = to;
}

Problem is that onHeightUpdate only gets called once, when the watch() is called. I've looked at the source of both AnimatedFloat and Tween, but everything seems ok there, so most likely I'm missing something. Any thoughts?