-
Notifications
You must be signed in to change notification settings - Fork 3
Basics 1 (Entry point)
#Tutorial navigation
- Previous: Home
- Current: Basics 1 (Entry point)
- [Next: Basics 2 (Game logic)](Basics 2 (Game logic))
#main()
The first thing to do when creating a game with this framework is create the Java main()
function. All you have to do is call Game.run(GameSettings settings)
. See the full working code:
package mygame;
import java.util.ArrayList;
import mygame.scene.MyFirstScene;
import org.unbiquitous.uImpala.engine.core.GameSettings;
import org.unbiquitous.uImpala.engine.core.Game;
import org.unbiquitous.uImpala.engine.io.KeyboardManager;
import org.unbiquitous.uImpala.engine.io.MouseManager;
import org.unbiquitous.uImpala.engine.io.ScreenManager;
import org.unbiquitous.uImpala.engine.io.SpeakerManager;
public class MyGame {
public static void main(final String[] args) {
Game.run(new GameSettings () {{
if (args.length == 2 && args[0].equals("-rp"))
put("root_path", args[1]);
put("first_scene", MyFirstScene.class);
put("input_managers", new ArrayList<Class<?>>() {{
add(KeyboardManager.class);
add(MouseManager.class);
}});
put("output_managers", new ArrayList<Class<?>>() {{
add(ScreenManager.class);
add(SpeakerManager.class);
}});
}});
}
}
-
The setting
"root_path"
is optional. If not added, the engine will consider the root path as"."
. This string will be the prefix for every path passed to load assets. Don't include trailing slashes in the root path. -
The setting
"first_scene"
tells the engine which scene must be instantiated to start the game (see the next tutorial for more details). -
The setting
"input_managers"
tells the engine which input managers it must instantiate for the game. The available input managers are:KeyboardManager
MouseManager
-
The setting
"output_managers"
tells the engine which output managers it must instantiate for the game. The available output managers are:ScreenManager
SpeakerManager
All these managers implement an internal interface
IOManager
and they will be covered later.You can add custom settings, because this
GameSettings
object will be available inside the classes you must implement.
#Tutorial navigation
- Previous: Home
- Current: Basics 1 (Entry point)
- [Next: Basics 2 (Game logic)](Basics 2 (Game logic))