Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added RenderMgr, which pushes world renders in sync with the flash fr…

…ame rate.

Signed-off-by: Ely Greenfield <egreenfi@adobe.com>
  • Loading branch information...
commit a86d7fa93f9abff6ac9d1f7916147f69cc9a986c 1 parent 9221854
Ely Greenfield authored
Showing with 75 additions and 1 deletion.
  1. +62 −0 src/M2D/worlds/RenderMgr.as
  2. +13 −1 src/M2D/worlds/World.as
View
62 src/M2D/worlds/RenderMgr.as
@@ -0,0 +1,62 @@
+package M2D.worlds
+{
+ import M2D.core.RenderTask;
+
+ import flash.display.DisplayObject;
+ import flash.display.DisplayObjectContainer;
+ import flash.display.Sprite;
+ import flash.display.Stage;
+ import flash.events.Event;
+
+ public class RenderMgr
+ {
+ private var stage:Stage;
+ private var root:DisplayObject;
+
+ public var autoRender:Boolean = true;
+ public var world:WorldBase;
+ public var renderEveryFrame:Boolean = true;
+
+ public function RenderMgr(world:WorldBase)
+ {
+ this.world = world;
+ }
+
+ public function init(root:DisplayObjectContainer):void
+ {
+ this.root = root;
+ root.addEventListener(Event.ENTER_FRAME,enterFrameHandler,false,0,true);
+ if(root.stage != null)
+ {
+ stage = root.stage;
+ if(autoRender)
+ stage.addEventListener(Event.RENDER,renderHandler,false,0,true);
+ }
+ else
+ root.addEventListener(Event.ADDED_TO_STAGE,addedToStageHandler,false,0,true);
+ }
+
+ public function addTask(task:RenderTask):void
+ {
+
+ }
+
+ private function enterFrameHandler(e:Event):void
+ {
+ if(renderEveryFrame)
+ stage.invalidate();
+ }
+
+ private function addedToStageHandler(e:Event):void
+ {
+ stage = e.currentTarget.stage as Stage;
+ stage.addEventListener(Event.RENDER,renderHandler,false,0,true);
+ }
+
+ private function renderHandler(e:Event):void
+ {
+ if(renderEveryFrame)
+ world.render();
+ }
+ }
+}
View
14 src/M2D/worlds/World.as
@@ -30,21 +30,33 @@
{
import M2D.particles.ParticleLibrary;
import M2D.sprites.SymbolLibrary;
+
+ import flash.display.DisplayObjectContainer;
+ import flash.display.Stage;
+ import flash.geom.Rectangle;
public class World extends WorldBase
{
public function World()
{
assetMgr = new AssetMgr(this);
+ renderMgr = new RenderMgr(this);
addJob(library);
addJob(particleLibrary);
}
+
+ override public function initContext(stage:Stage,container:DisplayObjectContainer,slot:int,bounds:Rectangle):void
+ {
+ renderMgr.init(container);
+ super.initContext(stage,container,slot,bounds);
+ }
// ======================================================================
// Constants
// ----------------------------------------------------------------------
public var assetMgr:AssetMgr;
public var particleLibrary:ParticleLibrary = new ParticleLibrary();
- public var library:SymbolLibrary = new SymbolLibrary();
+ public var library:SymbolLibrary = new SymbolLibrary();
+ public var renderMgr:RenderMgr;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.