Skip to content

Instantly share code, notes, and snippets.

Created December 23, 2012 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4363768 to your computer and use it in GitHub Desktop.
Save anonymous/4363768 to your computer and use it in GitHub Desktop.
package
{
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.geom.Rectangle;
import starling.core.Starling;
public class App extends Sprite
{
private var _starling:Starling;
public function App()
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
protected function init(event:Event = null):void
{
if (hasEventListener(Event.ADDED_TO_STAGE))
removeEventListener(Event.ADDED_TO_STAGE, init);
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.color = 0x000000;
stage.frameRate = 60;
_starling = new Starling(RodCalcApp, stage);
_starling.start();
stage.addEventListener(Event.RESIZE, onStageResize, false, int.MAX_VALUE, true);
stage.addEventListener(Event.DEACTIVATE, onStageDeactivate, false, 0, true);
}
private function onStageDeactivate(event:Event):void
{
_starling.stop();
stage.addEventListener(Event.ACTIVATE, onStageActivate, false, 0, true);
}
private function onStageResize(event:Event):void
{
if (stage.stageWidth < 256 || stage.stageHeight < 256) return;
_starling.stage.stageWidth = stage.stageWidth;
_starling.stage.stageHeight = stage.stageHeight;
const viewPort:Rectangle = _starling.viewPort;
viewPort.width = stage.stageWidth;
viewPort.height = stage.stageHeight;
try
{
_starling.viewPort = viewPort;
}
catch (error:Error)
{
}
}
private function onStageActivate(event:Event):void
{
stage.removeEventListener(Event.ACTIVATE, onStageActivate);
_starling.start();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment