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); | |
} | |
} |
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/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jgranick: Thanks, that was another guess -- the stage must have one sprite child at its root. I'll google the rest of the rules in the Flash API. I won't suggest a specific renaming of the ScreenResize class because I'm not familiar with all the rules, and their consequent impact on workflow/user scenarios/etc.
Digressing: I tried guessing your email because I'm curious how many packages in the standard NMEHaXe.org distribution are truly multi-platform (other than just nme.*). :-)