Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

listening to 'space' key to toggle stats display

  • Loading branch information...
commit ecb32b54261e1a99ed832a1d427a4c64608ca2d3 1 parent be5d7c9
@PrimaryFeather PrimaryFeather authored
Showing with 20 additions and 0 deletions.
  1. +20 −0 samples/demo/src/Game.as
View
20 samples/demo/src/Game.as
@@ -1,5 +1,6 @@
package
{
+ import flash.ui.Keyboard;
import flash.utils.getDefinitionByName;
import flash.utils.getQualifiedClassName;
@@ -18,6 +19,7 @@ package
import starling.display.Image;
import starling.display.Sprite;
import starling.events.Event;
+ import starling.events.KeyboardEvent;
import starling.text.TextField;
import starling.textures.Texture;
import starling.utils.VAlign;
@@ -79,6 +81,8 @@ package
}
addEventListener(Scene.CLOSING, onSceneClosing);
+ addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
+ addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
// show information about rendering method (hardware/software)
var driverInfo:String = Starling.context.driverInfo;
@@ -90,6 +94,22 @@ package
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
{
var button:Button = event.target as Button;
Please sign in to comment.
Something went wrong with that request. Please try again.