Home

pshtif edited this page Feb 13, 2012 · 22 revisions
Clone this wiki locally

Home

What is Genome2D:

Genome2D is a 2D framework written in ActionScript 3. The main reason for its creation was to leverage the new Stage3D APIs inside Flash Player 11 and AIR 3.x As it evolved the option to target older Flash Player/AIR version was added as well.

Genome2D is not trying to immitate Flash native display list but rather takes a different route, programmer can attach abstract nodes into render graph and plug components into the nodes that will define the actual functionality each particular node has. Its easy to sustain modularity in this component model when compared to inheritance model.

As already mentioned Genome2D itself is decoupled form the actual renderers this not only means that Genome2D is not dependant on Flash Player 11 it is also quite easily portable to other languages. The rendering is achieved through abstract layers, at the moment there are 2 renderers G2DStage3DContext (Flash Player 11/AIR3.x) and G2DBlittingContext (Flash Player 10/AIR2.x) For best performance always try to use G2DStage3DContext as it will leverage GPU acceleration.

Genome2D uses AS3Signals library from Robert Penner instead of Flash events model as signals proved to be way better than events when it comes to performance.

Getting Started:

  • Genome2D is the main class behind everything, at the moment its a singleton as there is no valid reason to have multiple instances of Genome2D running. Initialization of Genome2D is as simple as these 2 lines:

      Genome2D.getInstance().onInitialized.addOnce(onGenomeInitialized);
      Genome2D.getInstance().init(stage, G2DStage3DContext);
    
  • G2DNode is a rendergraph node class, you create and insert instances of this class into the render list, working with them is pretty similar to Flash native display list

  • G2DComponent is an abstract component class you actually don't create instances of this class but all components need to inherit this class

    • G2DRenderable is an abstract renderable component class, all the renderable components inherit this class and if you plan on creating a component that will override render you should inherit from this class, G2DNode can't have more than one G2DRenderable component attached to it

      • G2DSprite a simple renderable component that renders a G2DTexture instance specified
      • G2DMovieClip renderable component that renders sequence of G2DTextureAtlas subtextures in specified speed and order that can be defined and changed at runtime

This is just very limited list of components that Genome2D offers just to illustrate the architecture for other components check docs and examples.

For your assets to be rendered in Genome2D you need to convert them to bitmaps and then create textures. This is a different approach than in traditional display list and it has to do with how GPU model works. Its preferable to have your asset textures ready at initialization as invalidating textures during runtime may be taxing.

  • G2DTexture handling manipulation of a single texture, it may be a sole texture or a sub texture of parent texture atlas

  • G2DTextureAtlas handling texture atlas which refers to one or more textures it contains

Its preferable to use texture atlases where possible, simply put multiple assets inside a single atlas source as it will only upload a single GPU texture and speeds up rendering as Genome2D can batch draw calls internally.

  • G2DCamera last but not least this is a component handling actual view into the scene, you always need atleast one camera inside render graph to be able to see anything

Examples can be found here http://github.com/pshtif/Genome2D

Documentation can be found here http://www.flash-core.com/g2d/doc