Created
February 7, 2012 21:39
-
-
Save jgranick/1762234 to your computer and use it in GitHub Desktop.
How to dynamically handle different screen sizes (NME recipe)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import nme.display.Sprite; | |
import nme.display.StageAlign; | |
import nme.display.StageScaleMode; | |
import nme.Lib; | |
/** | |
* @author Joshua Granick | |
*/ | |
class ScreenResize extends Sprite { | |
private var setHeight:Float; | |
private var setWidth:Float; | |
public function new () { | |
super (); | |
initialize (); | |
resize (Lib.current.stage.stageWidth, Lib.current.stage.stageHeight); | |
Lib.current.stage.addEventListener (Event.RESIZE, stage_onResize); | |
} | |
private function initialize ():Void { | |
Lib.current.stage.align = StageAlign.TOP_LEFT; | |
Lib.current.stage.scaleMode = StageScaleMode.NO_SCALE; | |
} | |
private function resize (newWidth:Float, newHeight:Float):Void { | |
// position objects based on size | |
this.setHeight = newHeight; | |
this.setWidth = newWidth; | |
} | |
// Event Handlers | |
private function stage_onResize (event:Event):Void { | |
resize (stage.stageWidth, stage.stageHeight); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Well, I don't see a way to delete comments, so I'll just say I've sorted out which packages are cross-platform and which aren't. I found it useful to install extra libs from the command-line via "haxelib install ___". This page was helpful: http://www.haxenme.org/documentation/features/