Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 2.64 KB | None | 0 0
  1. package;
  2.  
  3. import flash.display.Sprite;
  4. import flash.display.StageAlign;
  5. import flash.display.StageScaleMode;
  6. import flash.events.Event;
  7. import flash.Lib;
  8. import flixel.FlxG;
  9. import flixel.FlxGame;
  10. import flixel.FlxState;
  11. import puzzleboss.Analytics;
  12. import puzzleboss.CrossPromotion;
  13. import puzzleboss.Images;
  14.  
  15. #if !flash
  16. import openfl.utils.JNI;
  17. #end
  18.  
  19. class Main extends Sprite
  20. {
  21.     var gameWidth:Int = 1280; // Width of the game in pixels (might be less / more in actual pixels depending on your zoom).
  22.     var gameHeight:Int = 800; // Height of the game in pixels (might be less / more in actual pixels depending on your zoom).
  23.     var initialState:Class<FlxState> = MenuState; // The FlxState the game starts with.
  24.     var zoom:Float = -1; // If -1, zoom is automatically calculated to fit the window dimensions.
  25.     var framerate:Int = 60; // How many frames per second the game should run at.
  26.     var skipSplash:Bool = false; // Whether to skip the flixel splash screen that appears in release mode.
  27.     var startFullscreen:Bool = false; // Whether to start the game in fullscreen on desktop targets
  28.    
  29.     // You can pretty much ignore everything from here on - your code should go in your states.
  30.    
  31.     public static function main():Void
  32.     {  
  33.         Lib.current.addChild(new Main());
  34.        
  35.         Images.initialize();
  36.         Analytics.initialize();
  37.         CrossPromotion.initialize();
  38.        
  39.        
  40.         Analytics.track("First Game Load");
  41.         FlxG.log.add("First Game Load");
  42.     }
  43.    
  44.     public function new()
  45.     {
  46.         super();
  47.        
  48.         if (stage != null)
  49.         {
  50.             init();
  51.         }
  52.         else
  53.         {
  54.             addEventListener(Event.ADDED_TO_STAGE, init);
  55.         }
  56.         addEventListener(Event.ENTER_FRAME, TrackMainActivity);
  57.     }
  58.    
  59.     private function TrackMainActivity(e:Event):Void
  60.     {
  61.         var jni = "com/scargames/SpotTheDifferences/amazon/MainActivity";
  62.         Reg.MainActivityTest = JNI.createStaticMethod(jni, "getActivity", "()Ljava/lang/String;");
  63.         trace("Current MainActivity state : " + Reg.MainActivityTest);
  64.     }
  65.    
  66.     private function init(?E:Event):Void
  67.     {
  68.         if (hasEventListener(Event.ADDED_TO_STAGE))
  69.         {
  70.             removeEventListener(Event.ADDED_TO_STAGE, init);
  71.         }
  72.        
  73.         setupGame();
  74.     }
  75.    
  76.     private function setupGame():Void
  77.     {
  78.         var stageWidth:Int = Lib.current.stage.stageWidth;
  79.         var stageHeight:Int = Lib.current.stage.stageHeight;
  80.  
  81.         if (zoom == -1)
  82.         {
  83.             var ratioX:Float = stageWidth / gameWidth;
  84.             var ratioY:Float = stageHeight / gameHeight;
  85.             zoom = Math.min(ratioX, ratioY);
  86.             gameWidth = Math.ceil(stageWidth / zoom);
  87.             gameHeight = Math.ceil(stageHeight / zoom);
  88.         }
  89.  
  90.         addChild(new FlxGame(gameWidth, gameHeight, initialState, zoom, framerate, framerate, skipSplash, startFullscreen));
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement