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.

bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , , ,

Related Posts:

5 Comments

  1. David T. Marchand on 29.09.2011 at 18:15 (Reply)

    It looks helpful! If only I knew what a Tweensy is…


    1. Gregory Weir on 29.09.2011 at 20:33 (Reply)

      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.


  2. axcho on 29.09.2011 at 22:23 (Reply)

    How does Tweensy compare with other libraries like TweenLite?


    1. Gregory Weir on 29.09.2011 at 23:46 (Reply)

      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. axcho on 30.09.2011 at 16:02 (Reply)

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


Sorry, the comment form is closed at this time.