Skip to content

Instantly share code, notes, and snippets.

@RobDangerous
Created December 6, 2013 15:05
Show Gist options
  • Save RobDangerous/7826146 to your computer and use it in GitHub Desktop.
Save RobDangerous/7826146 to your computer and use it in GitHub Desktop.
OpenFL fullscreen and resize example based on DisplayinABitmap sample.
package;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import openfl.Assets;
class Main extends Sprite {
private static var full: Bool = false;
public function new () {
super ();
var bitmap = new Bitmap (Assets.getBitmapData ("assets/openfl.png"));
addChild (bitmap);
bitmap.x = (stage.stageWidth - bitmap.width) / 2;
bitmap.y = (stage.stageHeight - bitmap.height) / 2;
for (mode in flash.system.Capabilities.screenModes) {
trace("w: " + mode.width + " h: " + mode.height + " refreshRate: " + mode.refreshRate);
}
stage.addEventListener(flash.events.KeyboardEvent.KEY_DOWN, keyDownHandler);
}
function resize(): Void {
stage.resize(400, 400);
}
function resolution(): Void {
if (full) {
stage.setFullscreen(false);
}
else {
stage.setFullscreen(true);
//stage.setResolution(800, 600);
var mode = new flash.system.ScreenMode();
mode.width = 800;
mode.height = 600;
mode.refreshRate = 60;
mode.format = flash.system.PixelFormat.BGRA8888;
stage.setScreenMode(mode);
}
full = !full;
}
function keyDownHandler(event: flash.events.KeyboardEvent): Void {
//resize();
resolution();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment