2D Accelerated Flash with M2D (Molehill)

25 Mar

UPDATE: Source code supplied at the bottom of the post.

Today I’ve been working with Ely Greenfield the author of the M2D framework that taps in Molehill, the GPU acceleration for Flash that’s currently in beta. I used Tom Krcha’s fork of Ely’s code to setup my scenes.

Wow. Wow, wow, and WOW.

I initially set up a basic rendering of LOTS of objects that move to see what the engine could handle. Then I added rotation, alpha and velocity and even animated sprite sheets. Ely updated the core framework, sending me updates and instructed me on how to set up the animations.

Here’s a video showing the results:

M2D tests from Terry Paton on Vimeo.


So what do I think?

  • These tests are not games, they are barely indicative of some animation techniques and data handling used in games. But by testing these to the extreme – 5,000+ objects at once – we get a good indication of what can be achieved.
  • Although molehill’s going to mean some amazing things for Flash 3D gaming, I think it’s going to have a huge impact of what we can achieve in 2D gaming as well. I heart 2D.
  • The performance of these tests well outperform what I have achieved in my own blitting engine, which I had either rotation OR alpha but not both – due to the amount of memory and handling I had to do to create the blits. M2D is handling this very well. This engine is still very much in development and giving Ely real test cases to optimise has meant great performance improvements already.
  • There is still a lot of work to be done, many types and sizes of sprites need to be tested together, along with post processing of effects over the top (like the rippling water effect I’m using in my Deep Sea Diver 2 game).


Check out these links for more about M2D:

UPDATE: Here’s the source code to the tests I made in the video. I’m not putting any help with how to set them up so you have to know what your doing. They are Flash Builder projects.
Please leave a comment if you try them :)


Posted in Game Dev


Tags: , , ,

  • Peter Macinkovic

    Incredible! With AIR 2.6 and all these Molehill developments I feel like a kid with too many toys to play with

  • theRemix

    that’s incredible and inspiring. makes me want to create some of my own interactive tests of M2D and post videos :)

  • wonderwhy-er

    Hmm, I have cursor effect experiment where I have 5k+ sprites with rotation/animation on screen. Smaller in size though which probably does not make big difference here

    It is and improvement but it does not strike me as 10 fold improvements or something so far. Except I guess it is easier to operate and eats less memory as it is closer to flash displaylist then bitmap blitting.

    I wonder if there is some GPU blitting like tricks that could push something like that even further.

  • Terry Paton

    Thanks for the comment, yeah there is still room for improvement with what were doing with molehill here. Thanks for sharing your example, give it a try using larger particle sizes (with multiples of them and animations), it pretty tough to get great performance of this size so I’d love to see what you come up with.

    I’m going to work further with Ely to optimise this framework, it’s VERY much a work in progress and I wouldn’t judge the final product based on what you see here.

  • Matt

    Thanks for posting the code. Noobs like myself appreciate this :)

  • snick

    Hi Terry i really enojoyed your experiments, really tnx you for sharing, i’m really looking forward to discover a concrete roadmap for the egreenfield’s m2d. I’m start trying to create a 2.5 engine ala isolib

  • Luke DeWitt

    Hi Terry,

    I’ve been trying to play around with M2D, but even in the “Hello, World” example, I am getting the following error that I cannot seem to figure out: 

    Error: Error #3608: Stream 0 is invalid. at flash.display3D::Context3D/drawTriangles() at M2D.core::GContext/blit2D()[] at M2D.sprites::SymbolLibrary/render()[] at M2D.worlds::WorldBase/render()[] at M2D.worlds::WorldBase/tick()[] at M2D.time::Clock/timerHandler()[] at flash.utils::Timer/_timerDispatch() at flash.utils::Timer/tick()

    I was wondering if you knew what might be causing this? I can’t seem to find the answer anywhere and have been searching for quite a while…

    Thank you,


  • Luke DeWitt

    Obviously 5 minutes after posting this I figured out the error (kind of)…

    By simply using the SWC rather than linking the src folder of the M2D framework to my project, it compiled and ran without any run time errors. I have seen this error a lot on some other sites, so I hope this helps people out!

  • Sevas


    Was trying to compile M2Test from your sources…
    Got an error:
    ReferenceError: Error #1056: Can’t create property viewPort in flash.display.Stage3D. at M2D.worlds::World/acquireContext()[/Users/tomkrcha/Documents/DEVEL/M2D/src/M2D/worlds/] at M2D.worlds::World/initContext()[/Users/tomkrcha/Documents/DEVEL/M2D/src/M2D/worlds/] at RenderScene/init()[] at flash.display::DisplayObjectContainer/addChild() at ExampleThousandsBig()[]

    Can you help me with that?

  • Sevas

    Can this be coz of new flash player beta?

  • Terry Paton

    Hey ya, yeah I suspect it’s because quite a bit has changed in Stage3D since I worked on this. Unfortunately it doesn’t look like M2D has updated :(