Skip to content

Commit

Permalink
now dispatching 'Event.RENDER' events on the Starling instace (closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
PrimaryFeather committed May 19, 2015
1 parent 94af14f commit 4030e74
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 13 additions & 4 deletions starling/src/starling/core/Starling.as
Expand Up @@ -61,6 +61,10 @@ package starling.core
/** Dispatched when a fatal error is encountered. The 'data' property contains an error string. */
[Event(name="fatalError", type="starling.events.Event")]

/** Dispatched when the display list is about to be rendered. This event provides the last
* opportunity to make changes before the display list is rendered. */
[Event(name="render", type="starling.events.Event")]

/** The Starling class represents the core of the Starling framework.
*
* <p>The Starling framework makes it possible to create 2D applications and games that make
Expand Down Expand Up @@ -460,7 +464,7 @@ package starling.core
}

/** Calls <code>advanceTime()</code> (with the time that has passed since the last frame)
* and <code>render()</code>. */
* and <code>render()</code>. */
public function nextFrame():void
{
var now:Number = getTimer() / 1000.0;
Expand Down Expand Up @@ -489,22 +493,27 @@ package starling.core
}

/** Renders the complete display list. Before rendering, the context is cleared; afterwards,
* it is presented. This can be avoided by enabling <code>shareContext</code>.*/
* it is presented (to avoid this, enable <code>shareContext</code>).
*
* <p>This method also dispatches an <code>Event.RENDER</code>-event on the Starling
* instance. That's the last opportunity to make changes before the display list is
* rendered.</p> */
public function render():void
{
if (!contextValid)
return;

makeCurrent();
updateViewPort();
mSupport.nextFrame();
dispatchEventWith(starling.events.Event.RENDER);

var scaleX:Number = mViewPort.width / mStage.stageWidth;
var scaleY:Number = mViewPort.height / mStage.stageHeight;

mContext.setDepthTest(false, Context3DCompareMode.ALWAYS);
mContext.setCulling(Context3DTriangleFace.NONE);

mSupport.nextFrame();
mSupport.stencilReferenceValue = 0;
mSupport.renderTarget = null; // back buffer
mSupport.setProjectionMatrix(
Expand Down
2 changes: 2 additions & 0 deletions starling/src/starling/events/Event.as
Expand Up @@ -57,6 +57,8 @@ package starling.events
public static const COMPLETE:String = "complete";
/** Event type for a (re)created stage3D rendering context. */
public static const CONTEXT3D_CREATE:String = "context3DCreate";
/** Event type that is dispatched by the Starling instance directly before rendering. */
public static const RENDER:String = "render";
/** Event type that indicates that the root DisplayObject has been created. */
public static const ROOT_CREATED:String = "rootCreated";
/** Event type for an animated object that requests to be removed from the juggler. */
Expand Down

0 comments on commit 4030e74

Please sign in to comment.