-
Notifications
You must be signed in to change notification settings - Fork 289
/
MenuState.hx
78 lines (66 loc) · 1.75 KB
/
MenuState.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package;
import flixel.FlxG;
import flixel.FlxState;
import flixel.text.FlxText;
import flixel.ui.FlxButton;
import flixel.util.FlxColor;
class MenuState extends FlxState
{
var titleText:FlxText;
var playButton:FlxButton;
var optionsButton:FlxButton;
#if desktop
var exitButton:FlxButton;
#end
override public function create()
{
titleText = new FlxText(20, 0, 0, "HaxeFlixel\nTutorial\nGame", 22);
titleText.alignment = CENTER;
titleText.screenCenter(X);
add(titleText);
playButton = new FlxButton(0, 0, "Play", clickPlay);
playButton.onUp.sound = FlxG.sound.load(AssetPaths.select__wav);
playButton.x = (FlxG.width / 2) - 10 - playButton.width;
playButton.y = FlxG.height - playButton.height - 10;
add(playButton);
optionsButton = new FlxButton(0, 0, "Options", clickOptions);
optionsButton.x = (FlxG.width / 2) + 10;
optionsButton.y = FlxG.height - optionsButton.height - 10;
add(optionsButton);
#if desktop
exitButton = new FlxButton(FlxG.width - 28, 8, "X", clickExit);
exitButton.loadGraphic(AssetPaths.button__png, true, 20, 20);
add(exitButton);
#end
if (FlxG.sound.music == null) // don't restart the music if it's already playing
{
#if flash
FlxG.sound.playMusic(AssetPaths.HaxeFlixel_Tutorial_Game__mp3, 1, true);
#else
FlxG.sound.playMusic(AssetPaths.HaxeFlixel_Tutorial_Game__ogg, 1, true);
#end
}
FlxG.camera.fade(FlxColor.BLACK, 0.33, true);
super.create();
}
function clickPlay()
{
FlxG.camera.fade(FlxColor.BLACK, 0.33, false, function()
{
FlxG.switchState(PlayState.new);
});
}
function clickOptions()
{
FlxG.camera.fade(FlxColor.BLACK, 0.33, false, function()
{
FlxG.switchState(OptionsState.new);
});
}
#if desktop
function clickExit()
{
Sys.exit(0);
}
#end
}