This repository has been archived by the owner on Sep 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Create the basics of the game
Malte edited this page Dec 17, 2018
·
9 revisions
Info this page is only applicable for Salty Engine >= 0.14.8-SNAPSHOT.
The main class of the game will extend de.edgelord.saltyengine.core.Game
.
For initializing your game, you can call Game#init(GameConfig)
.
package de.edgelord.saltyengine.example;
import de.edgelord.saltyengine.core.Game;
/**
* This is an example for the main class of a game.
*/
public class ExampleMain extends Game {
public static void main(String[] args) {
// The arguments for the used method GameConfig#config are:
// 1. float resWidth, which is the width of the resolution of the game and the starting width of the window. You should take something
// like 1920 and not 16, because all placing of objects in the world depends on that number
// 2. float resHeight, which is the height of the resolution of the game and the starting height of the window. You should take something
// like 1080 and not 9, because all placing of objects in the world depends on that number
// 3. String gameName, the name of the game. The window title and the save-file-folders depends on that
// 4. long fixedTickMillis, the milliseconds for the periodically physics calculations etc. Values from 1 - 10 are fine, the lower the
// number, the better is the performance of the game.
// You could also use the constrcutor of the class GameConfig
init(GameConfig.config(1920, 1080, "Salty Engine Example Game", 5));
}
}
The only thing left to do is to call Game.start()
.
The main
method could look like this (also from ExampleMain
):
public static void main(String[] args) {
init(GameConfig.config(1920, 1080, "Salty Engine Example Game", 5));
Game.start();
}
The whole class now looks like this:
package de.edgelord.saltyengine.example;
import de.edgelord.saltyengine.core.Game;
import de.edgelord.saltyengine.core.GameConfig;
/**
* This is an example for the main class of a game.
*/
public class ExampleMain extends Game {
public static void main(String[] args) {
init(GameConfig.config(1920, 1080, "Salty Engine Example Game", 5));
Game.start();
}
}
If you now run this, a window with the given size should appear in the middle of the Screen. It is currently completely empty and white. Currently...