Flixel and Tweensy Working Together

Are you using Flixel for Flash development? You should be.

Are you using Tweensy for easy programmatic Flash tweening? You should be.

Did you know that when Flixel loses focus and pauses, Tweensy doesn’t automatically pause? You should. It can cause some weird behavior.

I’ve figured out a simple fix that pauses Tweensy when Flixel doesn’t have focus. I just did it, so be aware that there may be some unexpected consequences of this that I don’t know about.

Put the following in your main class that extends FlxGame:

override protected function onFocus(FlashEvent:Event = null):void
{
    super.onFocus(FlashEvent);
    Tweensy.resume();
}

override protected function onFocusLost(FlashEvent:Event = null):void
{
    super.onFocusLost(FlashEvent);
    Tweensy.pause();
}

And that’s that. When Flixel pauses due to lost focus, Tweensy will as well, and when Flixel resumes, so will Tweensy. Just make sure you don’t get the “pause” and “resume” flipped; I did at first, and I couldn’t figure out what the hell was wrong.

5 thoughts on “Flixel and Tweensy Working Together

    1. Tweensy lets you easily animate stuff in Flash from code. So instead of setting up a timer and some update logic and so on to fade something out, you just do Tweensy.to(something, {alpha:0}) and it fades out.

    1. Tweensy uses virtually the same syntax as TweenLite and its cousins, and is totally drop-in-and-use. It has the slight advantage that its license (MIT) lets it be used in for-sale software without requiring a license fee.

      As far as performance, they seem comparable; TweenLite’s test says Tweensy’s a tiny bit slower, and Tweensy’s says that TweenLite is a little slower.

      The TweenLite family has much better examples and documentation. Tweensy’s basically got one guide page, API docs, and some demos with available source. But it really is simple to pick up.

      1. I see – thanks for the clarification. I didn’t realize that TweenLite had a more restrictive license. I’ll check out Tweensy sometime. :)

Comments are closed.