To run the game skeleton we made in previous chapter, we must choose graphics environment where the game will be performed. This graphics environment is initialized by one of GTGE engine, the graphics engine.
GTGE provides three graphics environments :
- Fullscreen Mode
In this mode, the game will enter fullscreen mode by changing the screen resolution and occupying the entire screen. This is the mode that used by commercial games. Game performance and quality is much better in this mode. - Windowed Mode
In this mode, the game is reside in a window, just like other common application. This mode is usually used to make a simple game or used only in development stage (when it's about to distribute the game, the game is changed to fullscreen mode). - Applet Mode
The game is embedded in a webpage. This mode is perfect for direct play in your website for a small or demo game.
Fullscreen and Windowed Mode
Use setup(Game, Dimension, boolean)
and start()
method from GameLoader
class to start a game in fullscreen or windowed mode :
class :: GameLoader
Syntax:
public void setup(Game game,
Dimension d,
boolean fullscreen);
public void start();
whereas :
game = the game (subclass of Game
class)
d = the dimension of the game
fullscreen = use fullscreen mode or not (windowed mode)
For example:
initialize and run YourGame.java in 640x480 dimension, fullscreen mode
GameLoader game = new GameLoader();
game.setup(new YourGame(), new Dimension(640,480), true);
game.start();
The game skeleton run in 640x480, fullscreen mode :
Tutorial5_1.java [view online]
file :: YourGame.java // JFC import java.awt.Graphics2D; import java.awt.Dimension; // GTGE import com.golden.gamedev.Game; import com.golden.gamedev.GameLoader; public class YourGame extends Game { /****************************************************************************/ /**************************** GAME SKELETON *********************************/ /****************************************************************************/ public void initResources() { } public void update(long elapsedTime) { } public void render(Graphics2D g) { } /****************************************************************************/ /***************************** START-POINT **********************************/ /****************************************************************************/ public static void main(String[] args) { GameLoader game = new GameLoader(); game.setup(new YourGame(), new Dimension(640,480), true); game.start(); } }This game skeleton can be compiled and run. It will show an empty game.
To change the graphics environment to windowed mode, change the
true
value to false
, game.setup(new YourGame(), new Dimension(640,480), false);
really simple isn't it?!Tutorial5_2.java [view online]
Applet Mode
To run the game in Applet environment, you need to subclass GameLoader
class and override createAppletGame()
method :
Tutorial5_3.java [view online]
file :: YourGameApplet.java // GTGE import com.golden.gamedev.Game; import com.golden.gamedev.GameLoader; public class YourGameApplet extends GameLoader { protected Game createAppletGame() { return new YourGame(); } }
To embed the game to your html page, add this applet tag :
file :: webpage (.html,.php,...) Syntax: <applet code="YourGameApplet.class" archive="[your_game_lib],[GTGE_lib]" width="[width]" height="[height]"> </applet> whereas : your_game_lib = the game jar (.jar) GTGE_lib = the GTGE library (.jar) width = the game width height = the game height For example: show YourGame.java in web page with 640x480 dimension using GTGE v0.2.0 <html> <applet code="YourGameApplet.class" archive="yourgamearchive.jar,golden_0_2_0.jar" width="640" height="480"> </applet> </html>