Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package;
- import flash.display.Sprite;
- import flash.display.StageAlign;
- import flash.display.StageScaleMode;
- import flash.events.Event;
- import flash.Lib;
- import flixel.FlxG;
- import flixel.FlxGame;
- import flixel.FlxState;
- import puzzleboss.Analytics;
- import puzzleboss.CrossPromotion;
- import puzzleboss.Images;
- #if !flash
- import openfl.utils.JNI;
- #end
- 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 = 800; // Height of the game in pixels (might be less / more in actual pixels depending on your zoom).
- var initialState:Class<FlxState> = MenuState; // 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 = false; // 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());
- Images.initialize();
- Analytics.initialize();
- CrossPromotion.initialize();
- Analytics.track("First Game Load");
- FlxG.log.add("First Game Load");
- }
- public function new()
- {
- super();
- if (stage != null)
- {
- init();
- }
- else
- {
- addEventListener(Event.ADDED_TO_STAGE, init);
- }
- addEventListener(Event.ENTER_FRAME, TrackMainActivity);
- }
- private function TrackMainActivity(e:Event):Void
- {
- var jni = "com/scargames/SpotTheDifferences/amazon/MainActivity";
- Reg.MainActivityTest = JNI.createStaticMethod(jni, "getActivity", "()Ljava/lang/String;");
- trace("Current MainActivity state : " + Reg.MainActivityTest);
- }
- 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);
- }
- addChild(new FlxGame(gameWidth, gameHeight, initialState, zoom, framerate, framerate, skipSplash, startFullscreen));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement