GTGE is a pack of Java functions for making 2D game. In order to use those functions, technically GTGE must be installed first. In Java context, it means insert GTGE library into the game classpath.
There are 2 steps to run a GTGE game :
- Compile : convert the game source code (.java) into bytecode (.class).
- Run : run the bytecode (.class).
Compile
Tutorial2_1.batThe first step is converting the game source code (.java) into bytecode (.class) by using Java compiler (java_path\bin\javac.exe) that included in Java SDK (see previous chapter).
Because we have set the system path to this Java compiler in previous chapter, this compiler (javac.exe) can be used within any directory.
How to compile the game source code :
file :: javac.exe
Syntax:
javac -classpath %CLASSPATH%;.;[GTGE_dir]/golden_x_x_x.jar [game_source_code]
whereas :
%CLASSPATH% = system classpath (we have set this on autoexec.bat in previous chapter)
. = current directory (where the game source code is located)
[GTGE_dir] = where GTGE library is located (golden_x_x_x.jar)
[game_source_code] = the game source code (.java)
For example:
compile YourGame.java
with GTGE v0.2.0 - C:\GTGE\golden_0_2_0.jar
javac -classpath %CLASSPATH%;.;C:/GTGE/golden_0_2_0.jar YourGame.java
In this example, YourGame.java
is compiled into YourGame.class
.
Execute/Run
Tutorial2_2.batThe next step is running the compiled source code (bytecode) by using Java launcher (java_path\bin\java.exe), also included in Java SDK.
How to run the game bytecode :
file :: java.exe
Syntax:
java -classpath %CLASSPATH%;.;[GTGE_dir]/golden_x_x_x.jar [game_byte_code]
whereas :
%CLASSPATH% = system classpath (we have set this on autoexec.bat in previous chapter)
. = current directory (where the class file is located)
[GTGE_dir] = where GTGE library is located (golden_x_x_x.jar)
[game_byte_code] = the game bytecode (.class), omit the .class
For example:
run YourGame.class
with GTGE v0.2.0 - C:\GTGE\golden_0_2_0.jar
java -classpath %CLASSPATH%;.;C:/GTGE/golden_0_2_0.jar YourGame
In this example, the game YourGame.class
will be executed.
For practice, try to compile and run this tutorial source code (located at [src] directory).
Having trouble with compiling/running the game? Post the problem in GTGE message board.