Skip to content

Commit

Permalink
listening to 'space' key to toggle stats display
Browse files Browse the repository at this point in the history
  • Loading branch information
PrimaryFeather committed Apr 16, 2012
1 parent be5d7c9 commit ecb32b5
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions samples/demo/src/Game.as
@@ -1,5 +1,6 @@
package package
{ {
import flash.ui.Keyboard;
import flash.utils.getDefinitionByName; import flash.utils.getDefinitionByName;
import flash.utils.getQualifiedClassName; import flash.utils.getQualifiedClassName;


Expand All @@ -18,6 +19,7 @@ package
import starling.display.Image; import starling.display.Image;
import starling.display.Sprite; import starling.display.Sprite;
import starling.events.Event; import starling.events.Event;
import starling.events.KeyboardEvent;
import starling.text.TextField; import starling.text.TextField;
import starling.textures.Texture; import starling.textures.Texture;
import starling.utils.VAlign; import starling.utils.VAlign;
Expand Down Expand Up @@ -79,6 +81,8 @@ package
} }


addEventListener(Scene.CLOSING, onSceneClosing); addEventListener(Scene.CLOSING, onSceneClosing);
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);


// show information about rendering method (hardware/software) // show information about rendering method (hardware/software)
var driverInfo:String = Starling.context.driverInfo; var driverInfo:String = Starling.context.driverInfo;
Expand All @@ -90,6 +94,22 @@ package
mMainMenu.addChild(infoText); mMainMenu.addChild(infoText);
} }


private function onAddedToStage(event:Event):void
{
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKey);
}

private function onRemovedFromStage(event:Event):void
{
stage.removeEventListener(KeyboardEvent.KEY_DOWN, onKey);
}

private function onKey(event:KeyboardEvent):void
{
if (event.keyCode == Keyboard.SPACE)
Starling.current.showStats = !Starling.current.showStats;
}

private function onButtonTriggered(event:Event):void private function onButtonTriggered(event:Event):void
{ {
var button:Button = event.target as Button; var button:Button = event.target as Button;
Expand Down

0 comments on commit ecb32b5

Please sign in to comment.