Game apps for smartphones and tablets |
|
Research project PHBern |
The most important classes of the class library JDroidLib are GameGrid and Actor. With the aid of GameGrid, the game window is created. All moving figures and objects that appear in the game window are actors. The class GameGrid provides a graph window. The window is built up as a grid and therefore consists of a certain number of horizontal and vertical square cells. The cell size and number in vertical and horizontal direction are freely selectable. For certain applications, relatively big cells are more appropriate (grid games), for other applications, only 1 pixel cells should be used. In order to position things within the graph window, the cell coordinates are used. In most examples, the application class is derived from extends GameGrid from the class GameGrid. Therewith, all methods of the class GameGrid are available. With super(), the constructor of GameGrid is initialized. In the following example, the standard template Im MyAndroid.java that appears as template in the online editor is used.
|
![]() |
package online.app | Package indicates the subdirectories in which the application is saved. This indication is necessary with Android apps |
public class MyAndroid extends GameGrid | The application class is diverted from the class GameGrid and therefore inherits all (non private methods) of this class |
super(8, 8, 0, Color.RED, true) | Initializes a graph window with 8 horizontal and 8 vertical cells. The third parameter is the cell size. If there is a 0, the cell size is calculated automatically, so that the 8 cells fit in the disply. The grid lines are red. Parameter true activates the navigation |
doRun() | Starts the animation. Since there are no actors yet in this example, nothing happens |
Two examples:
super(8, 8, 0, Color.RED, "reef", true); | super(10, 10, 0, Color.GREEN, true, true); | |
Window with backround image |
Window with buttons | |
Some background images are saved on the webserver (see image library), but it is as well possible to use own images (more...). |
![]() |