|
GTGE API | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
java.awt.Panel
java.applet.Applet
com.golden.gamedev.engine.graphics.AppletMode
com.golden.gamedev.GameLoader
public class GameLoader
GameLoader class is the class that manages Game
class initialization.
GameLoader handles Game class
graphics engine
initialization, validating user Java version,
and also catch any unexpected runtime error in Applet mode.
Example of how-to-use GameLoader in application mode :
public class YourGame extends Game {
public static void main(String[] args) {
GameLoader game = new GameLoader();
// init game with fullscreen mode, 640x480 screen resolution
game.setup(new YourGame(), new Dimension(640,480), true);
game.start();
}
}
In applet mode, GameLoader class need to be subclassed and
override createAppletGame() method to return the actual game :
public class YourGameApplet extends GameLoader {
protected Game createAppletGame() {
return new YourGame();
}
}
Then point the applet tag code to that GameLoader subclass :
<html>
<head>
</head>
<body>
<applet code="gamepackage.YourGameApplet.class"
archive="yourgamearchive.jar,golden_x_x_x.jar"
width=640 height=480>
</applet>
</body>
</html>
setup(Game, Dimension, boolean, boolean),
start(),
createAppletGame(),
Serialized Form| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class java.applet.Applet |
|---|
Applet.AccessibleApplet |
| Nested classes/interfaces inherited from class java.awt.Panel |
|---|
Panel.AccessibleAWTPanel |
| Nested classes/interfaces inherited from class java.awt.Container |
|---|
Container.AccessibleAWTContainer |
| Nested classes/interfaces inherited from class java.awt.Component |
|---|
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
| Field Summary | |
|---|---|
protected Game |
game
The game (subclass of Game class) initialized by this
GameLoader. |
protected BaseGraphics |
gfx
Graphics engine loaded by this GameLoader. |
static String |
JAVA_VERSION
The installed Java Virtual Machine (JVM) version on player machine. |
String |
MINIMUM_VERSION
The minimum Java version that the game known can be run properly. |
| Fields inherited from class com.golden.gamedev.engine.graphics.AppletMode |
|---|
CONFIG, DEVICE |
| Fields inherited from class java.awt.Component |
|---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| Fields inherited from interface java.awt.image.ImageObserver |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
|---|---|
GameLoader()
Constructs new GameLoader. |
|
| Method Summary | |
|---|---|
protected Game |
createAppletGame()
To play game in applet environment, GameLoader class need to
be subclassed and this method need to be override to return the actual
game object. |
Game |
getGame()
Returns the game associated with this game loader or null if this game loader has not loaded any game. |
String |
getGraphicsDescription()
Returns graphics engine description, for example: fullscreen, windowed, applet, fullscreen with bufferstrategy, etc. |
void |
paint(Graphics g)
Draw essentials informations in applet game, for example : draw info when waiting the game to show up, or when the game is throwing an exception. |
void |
run()
In applet environment the game have to be started in a thread, this is the thread implementation that actually launch the applet game. |
void |
setup(Game game,
Dimension d,
boolean fullscreen)
Initializes graphics engine with specified size, mode, using bufferstrategy by default, and associates it with specified Game object. |
void |
setup(Game game,
Dimension d,
boolean fullscreen,
boolean bufferstrategy)
Initializes graphics engine with specified size, mode, bufferstrategy, and associates it with specified Game object. |
void |
start()
Starts the game that have been loaded by this loader. |
void |
stop()
Stops the game from running, to resume the game call start()
again, please see note below. |
protected boolean |
validJavaVersion()
Returns whether the Java version is passed the minimum Java version requirement or not. |
void |
windowActivated(WindowEvent e)
Do nothing. |
void |
windowClosed(WindowEvent e)
Do nothing. |
void |
windowClosing(WindowEvent e)
If the user pressing frame close button while playing in WindowedMode or FullScreenMode,
this method will receive the closing event. |
void |
windowDeactivated(WindowEvent e)
Do nothing. |
void |
windowDeiconified(WindowEvent e)
Do nothing. |
void |
windowIconified(WindowEvent e)
Do nothing. |
void |
windowOpened(WindowEvent e)
Do nothing. |
| Methods inherited from class com.golden.gamedev.engine.graphics.AppletMode |
|---|
cleanup, destroy, flip, getBackBuffer, getComponent, getSize, getWindowIcon, getWindowTitle, setWindowIcon, setWindowTitle |
| Methods inherited from class java.applet.Applet |
|---|
getAccessibleContext, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, init, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus |
| Methods inherited from class java.awt.Panel |
|---|
addNotify |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final String JAVA_VERSION
public String MINIMUM_VERSION
How to change the minimum Java version :
GameLoader game = new GameLoader();
game.MINIMUM_VERSION = "1.4.2";
game.setup(....);
game.start();
In applet mode, minimum version is specified in applet param 'MINIMUM'
tag.
<PARAM NAME="MINIMUM" VALUE="1.4.2">
protected BaseGraphics gfx
GameLoader.
protected Game game
Game class) initialized by this
GameLoader.
| Constructor Detail |
|---|
public GameLoader()
GameLoader.
setup(Game, Dimension, boolean, boolean),
start()| Method Detail |
|---|
public void start()
start in class AppletModesetup(Game, Dimension, boolean, boolean)public void stop()
start()
again, please see note below. By default this method is only called by browser in Applet Game.
Browser calls this method automatically when the web page contain the
game is been replaced by another page and just before the applet is going
to be destroyed.
The start() method is also automatically called by the
browser each time the applet is being revisited.
stop in class Appletpublic final void run()
run in interface Runnableprotected Game createAppletGame()
GameLoader class need to
be subclassed and this method need to be override to return the actual
game object. For example :
public class YourGameApplet extends GameLoader {
protected Game createAppletGame() {
return new YourGame();
}
}
public void setup(Game game,
Dimension d,
boolean fullscreen,
boolean bufferstrategy)
Game object.
public void setup(Game game,
Dimension d,
boolean fullscreen)
Game object.
public Game getGame()
public void paint(Graphics g)
paint in class Containerprotected boolean validJavaVersion()
Called this method before load the game to be sure the user machine has the minimum Java version to play the game.
MINIMUM_VERSIONpublic String getGraphicsDescription()
BaseGraphics
getGraphicsDescription in interface BaseGraphicsgetGraphicsDescription in class AppletModepublic void windowClosing(WindowEvent e)
WindowedMode or FullScreenMode,
this method will receive the closing event. In this implementation, pressing frame close button will instantly close any playing game by calling the game finish() method.
To avoid the game closed when frame close button is pressed, simply override this method or remove this listener from the graphics engine :
GameLoader game = new GameLoader();
game.setup(...);
BaseGraphics gfx = game.getGame().bsGraphics;
// only fullscreen and window mode the game is using frame
if (gfx instanceof FullScreenMode) {
// remove this listener
((FullScreenMode) gfx).getFrame().removeWindowListener(game);
}
if (gfx instanceof WindowedMode) {
// remove this listener
((WindowedMode) gfx).getFrame().removeWindowListener(game);
}
game.start();
windowClosing in interface WindowListenerpublic void windowOpened(WindowEvent e)
windowOpened in interface WindowListenerpublic void windowClosed(WindowEvent e)
windowClosed in interface WindowListenerpublic void windowIconified(WindowEvent e)
windowIconified in interface WindowListenerpublic void windowDeiconified(WindowEvent e)
windowDeiconified in interface WindowListenerpublic void windowActivated(WindowEvent e)
windowActivated in interface WindowListenerpublic void windowDeactivated(WindowEvent e)
windowDeactivated in interface WindowListener
|
GTGE API | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||