-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMain.hx
59 lines (47 loc) · 1.79 KB
/
Main.hx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package;
import flash.Lib;
import flash.display.Sprite;
import flash.events.Event;
import flixel.FlxG;
import flixel.FlxGame;
import flixel.FlxState;
/**
* Sets up the basic HaxeFlixel demo state.
* @author Sam Twidale (https://samcodes.co.uk/)
*/
class Main extends Sprite {
var gameWidth:Int = 1800; // Width of the game in pixels (might be less / more in actual pixels depending on your zoom).
var gameHeight:Int = 1200; // Height of the game in pixels (might be less / more in actual pixels depending on your zoom).
var initialState:Class<FlxState> = PlayState;
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
static public function main():Void {
Lib.current.addChild(new Main());
}
public function new() {
super();
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);
}
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));
FlxG.fixedTimestep = false;
}
}