From 2278d22a5a06dbf38b05fc8da516e6ab83513c0b Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Tue, 16 Feb 2021 01:53:25 -0500 Subject: [PATCH] mobile bullshit cookin in progress??? --- Project.xml | 12 +++++----- source/Main.hx | 60 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 65 insertions(+), 7 deletions(-) diff --git a/Project.xml b/Project.xml index b525b57c5..9ebcdccdb 100644 --- a/Project.xml +++ b/Project.xml @@ -2,7 +2,7 @@ - + @@ -27,7 +27,7 @@ - + @@ -94,9 +94,9 @@ - - - + + + @@ -121,7 +121,7 @@ - + diff --git a/source/Main.hx b/source/Main.hx index 13376db44..7f287f87e 100644 --- a/source/Main.hx +++ b/source/Main.hx @@ -1,15 +1,73 @@ package; import flixel.FlxGame; +import flixel.FlxState; +import openfl.Assets; +import openfl.Lib; import openfl.display.FPS; import openfl.display.Sprite; +import openfl.events.Event; class Main extends Sprite { + var gameWidth:Int = 1280; // Width of the game in pixels (might be less / more in actual pixels depending on your zoom). + var gameHeight:Int = 720; // Height of the game in pixels (might be less / more in actual pixels depending on your zoom). + var initialState:Class = TitleState; // The FlxState the game starts with. + var zoom:Float = -1; // If -1, zoom is automatically calculated to fit the window dimensions. + var framerate:Int = 60; // How many frames per second the game should run at. + var skipSplash:Bool = true; // Whether to skip the flixel splash screen that appears in release mode. + var startFullscreen:Bool = false; // Whether to start the game in fullscreen on desktop targets + + // You can pretty much ignore everything from here on - your code should go in your states. + + public static function main():Void + { + Lib.current.addChild(new Main()); + } + public function new() { super(); - addChild(new FlxGame(0, 0, TitleState)); + + if (stage != null) + { + init(); + } + else + { + addEventListener(Event.ADDED_TO_STAGE, init); + } + } + + private function init(?E:Event):Void + { + if (hasEventListener(Event.ADDED_TO_STAGE)) + { + removeEventListener(Event.ADDED_TO_STAGE, init); + } + + setupGame(); + } + + private function setupGame():Void + { + var stageWidth:Int = Lib.current.stage.stageWidth; + var stageHeight:Int = Lib.current.stage.stageHeight; + + if (zoom == -1) + { + var ratioX:Float = stageWidth / gameWidth; + var ratioY:Float = stageHeight / gameHeight; + zoom = Math.min(ratioX, ratioY); + gameWidth = Math.ceil(stageWidth / zoom); + gameHeight = Math.ceil(stageHeight / zoom); + } + + #if !debug + initialState = TitleState; + #end + + addChild(new FlxGame(gameWidth, gameHeight, initialState, zoom, framerate, framerate, skipSplash, startFullscreen)); #if !mobile addChild(new FPS(10, 3, 0xFFFFFF));