2D Sprite Sheets with Molehill

Thibault posted a 2D sprite demo with his announcement. How was this done? Well, it’s rather simple: here is the code for it.

I essentially implemented a new class which works fairly similarly to a Sprite object but called it Sprite3D instead. It supports scale, rotation, alpha and color transforms. All the basic stuff you need. Of course you could easily extend this to support even more things like effects. Anyhow, hopefully looking at this code will give you an idea of how to do 2D graphics with Molehill. It’s much simpler than doing 3D for sure, especially the shaders are much easier to understand.

The sprite sheet itself was created with a combination of tools: SWFSheet and TexturePacker. Both of these are free. Within TexturePacker I exported to the cocos2d plist sprite sheet format which is parsed and managed in the Sprite3D class.

Oh, if you wonder: That ‘thedog.atf’ file is using a new file format we are introducing specifically for texture data. We will make the encoding tools available for this very soon at which point I will explain more of how these work.

Here is what you should see when you run this demonstration:

Leave a comment

15 Comments.

  1. Does Adobe plan to post the Standalone/Projector Flash Player builds? Is there way to get access to these if adobe is not planning on posting them?
    Thanks,
    Sean

  2. I recently filed http://bugs.adobe.com/jira/browse/FP-6216 for native jpeg and png encoding, what about “atf” encoding?

    • ATF encoding is too expensive to do client side. We will provide off-line tools to deal with ATF encoding.

      Thanks for the feature request though. JPEG and PNG are definitely more realistic formats though much more difficult to support on mobile devices.

  3. Yeah, having JPEG/PNG encoding inside the native Flash Player (not just AIR) would be particularly nice to have.

    The same goes for some built-in classes/methods for mails and cryptography. I had to rely back in the day for my own “Alchemy memory-enabled” library for 3DES back in the day, and even so it was not that fast (although a lot faster than a common AS3 library).

    These are the sort of things where SL is ahead of Flash. The player team should care a bit more about LOB apps.

    Just my humble opinion.

    I guess I’ll have to make some feature request as well.

  4. I was trying to play around with this example and the Texture method uploadCompressedTextureFromByteArray only works with your .atf file, but I have no way to create one on my own!

    I tried converting the png spritesheet to both bitmap data and byte array, but uploadFromBitmapData and uploadFromByteArray just throw back errors when Sprite3D tries to render it:
    Error: Error #3700: A texture sampler binds an incomplete texture. Make sure to upload(). All miplevels are required when mipmapping is enabled.
    at flash.display3D::Context3D/drawTriangles()
    at com.adobe.utils::Sprite3D/render()

    Not sure what that means, but I’d love to play around with this soon!

  5. Same problem as Scott, when I substitute the texture for a PNG and use uploadFromBitmapData I get the same error on the _context3D.drawTriangles command.

    Any help would be appreciated.

  6. Nice code example, Tinic.

    But I’m still puzzled, why should developers use a 3D API to do hardware accelerated 2D in Flash. Isn’t it a bit of a shame the standard display list APIs, that the entire Flash product ecosystem is built around, doesn’t make use of it?

    What are Adobe’s plans in this direction?