+95
-0
lines changedFilter options
+95
-0
lines changed Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
1
+
/*
2
+
* FXGL - JavaFX Game Library. The MIT License (MIT).
3
+
* Copyright (c) AlmasB (almaslvl@gmail.com).
4
+
* See LICENSE for details.
5
+
*/
6
+
7
+
package sandbox;
8
+
9
+
import com.almasb.fxgl.app.GameApplication;
10
+
import com.almasb.fxgl.dsl.FXGL;
11
+
import javafx.application.Application;
12
+
import javafx.scene.Parent;
13
+
import javafx.scene.Scene;
14
+
import javafx.scene.control.Button;
15
+
import javafx.scene.layout.HBox;
16
+
import javafx.scene.layout.Pane;
17
+
import javafx.scene.layout.VBox;
18
+
import javafx.stage.Stage;
19
+
import sandbox.test3d.Model3DSample;
20
+
21
+
import java.util.List;
22
+
import java.util.function.Supplier;
23
+
24
+
/**
25
+
* @author Almas Baimagambetov (almaslvl@gmail.com)
26
+
*/
27
+
public class RestartableSample extends Application {
28
+
@Override
29
+
public void start(Stage stage) throws Exception {
30
+
stage.setScene(new Scene(createContent()));
31
+
stage.show();
32
+
}
33
+
34
+
private Parent createContent() {
35
+
List<Supplier<GameApplication>> games = List.of(
36
+
SpriteSheetAnimationApp::new,
37
+
ScrollingBackgroundSample::new,
38
+
PlatformerSample::new,
39
+
TiledMapSample::new,
40
+
Model3DSample::new
41
+
);
42
+
43
+
var root = new VBox();
44
+
root.setPrefSize(1280, 720);
45
+
46
+
var hbox = new HBox(5);
47
+
48
+
for (int i = 0; i < games.size(); i++) {
49
+
var btn = new Button("game " + i);
50
+
var gameConstructor = games.get(i);
51
+
52
+
btn.setOnAction(e -> {
53
+
GameApplication.embeddedShutdown();
54
+
55
+
var pane = GameApplication.embeddedLaunch(gameConstructor.get());
56
+
57
+
root.getChildren().set(1, pane);
58
+
});
59
+
60
+
hbox.getChildren().add(btn);
61
+
}
62
+
63
+
root.getChildren().addAll(hbox, new Pane());
64
+
return root;
65
+
}
66
+
67
+
@Override
68
+
public void stop() throws Exception {
69
+
FXGL.getGameController().exit();
70
+
}
71
+
72
+
public static void main(String[] args) {
73
+
launch(args);
74
+
}
75
+
}
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
8
8
import com.almasb.fxgl.core.reflect.ReflectionUtils;
9
9
import com.almasb.fxgl.core.util.Platform;
10
10
import com.almasb.fxgl.dev.profiling.ProfilerService;
11
+
import com.almasb.fxgl.dsl.FXGL;
11
12
import com.almasb.fxgl.generated.BuildProperties;
12
13
import com.almasb.fxgl.logging.*;
13
14
@@ -142,6 +143,19 @@ private void initLogger(ReadOnlyGameSettings settings) {
142
143
log.debug("Logging settings\n" + settings);
143
144
}
144
145
146
+
/**
147
+
* Shuts down currently running embedded FXGL instance.
148
+
* No-op if no FXGL instance is launched in embedded mode.
149
+
* After this call, another {@link #embeddedLaunch(GameApplication)} can be started.
150
+
* Note that after FXGL is no longer needed (no launch calls will be made),
151
+
* FXGL.getGameController().exit() should be called.
152
+
*/
153
+
public static void embeddedShutdown() {
154
+
FXGL.extract$fxgl();
155
+
156
+
Logger.removeAllOutputs();
157
+
}
158
+
145
159
/**
146
160
* Initialize app settings.
147
161
*/
Original file line number Diff line number Diff line change
@@ -92,6 +92,12 @@ class FXGL private constructor() { companion object {
92
92
app = gameApp
93
93
}
94
94
95
+
@JvmStatic
96
+
internal fun extract() {
97
+
if (this::engine.isInitialized)
98
+
engine.stopLoopAndExitServices()
99
+
}
100
+
95
101
private val controller = object : GameController {
96
102
override fun gotoIntro() {
97
103
getWindowService().gotoIntro()
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4