|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.newdawn.slick.GameContainer
public abstract class GameContainer
A generic game container that handles the game loop, fps recording and managing the input system
Field Summary | |
---|---|
protected boolean |
alwaysRender
True if we should render when not focused |
protected boolean |
clearEachFrame
True if we should clear the screen each frame |
protected boolean |
forceExit
True if we should force exit |
protected int |
fps
The current count of FPS |
protected Game |
game
The game being managed |
protected static SGL |
GL
The renderer to use for all GL operations |
protected int |
height
The height of the display |
protected Input |
input
The input system to pass to the game |
protected long |
lastFPS
The last time the FPS recorded |
protected long |
lastFrame
The time the last frame was rendered |
protected Game |
lastGame
The last game started |
protected long |
maximumLogicInterval
The maximum logic update interval |
protected long |
minimumLogicInterval
The minimum logic update interval |
protected boolean |
paused
True if the game is paused |
protected int |
recordedFPS
The last recorded FPS |
protected boolean |
running
True if we're currently running the game loop |
protected int |
samples
The number of samples we'll attempt through hardware |
protected static org.lwjgl.opengl.Drawable |
SHARED_DRAWABLE
The shared drawable if any |
protected boolean |
smoothDeltas
Smoothed deltas requested |
protected static boolean |
stencil
True if we require stencil bits |
protected long |
storedDelta
The stored delta |
protected boolean |
supportsMultiSample
True if this context supports multisample |
protected int |
targetFPS
The FPS we want to lock to |
protected boolean |
vsync
True if vsync has been requested |
protected int |
width
The width of the display |
Constructor Summary | |
---|---|
protected |
GameContainer(Game game)
Create a new game container wrapping a given game |
Method Summary | |
---|---|
static void |
enableSharedContext()
Enable shared OpenGL context. |
static void |
enableStencil()
|
protected void |
enterOrtho()
Enter the orthographic mode |
protected void |
enterOrtho(int xsize,
int ysize)
Enter the orthographic mode |
void |
exit()
Cause the game to exit and shutdown cleanly |
boolean |
getAlwaysRender()
True if this container should render when it has focus |
float |
getAspectRatio()
Get the aspect ratio of the screen |
static int |
getBuildVersion()
Get the build number of slick |
Font |
getDefaultFont()
Get the default system font |
protected int |
getDelta()
Retrieve the time taken to render the last frame, i.e. |
int |
getFPS()
Get the current recorded FPS (frames per second) |
Graphics |
getGraphics()
Get the graphics context used by this container. |
int |
getHeight()
Get the height of the game canvas |
Input |
getInput()
Get the input system |
float |
getMusicVolume()
Retrieve the current default volume for music |
int |
getSamples()
The number of samples we're attempting to performing using hardware multisampling |
abstract int |
getScreenHeight()
Get the height of the standard screen resolution |
abstract int |
getScreenWidth()
Get the width of the standard screen resolution |
static org.lwjgl.opengl.Drawable |
getSharedContext()
Get the context shared by all containers |
float |
getSoundVolume()
Retrieve the current default volume for sound fx |
long |
getTime()
Get the accurate system time |
int |
getWidth()
Get the width of the game canvas |
abstract boolean |
hasFocus()
Check if the game currently has focus |
protected void |
initGL()
Initialise the GL context |
protected void |
initSystem()
Initialise the system components, OpenGL and OpenAL. |
boolean |
isFullscreen()
Check if the display is in fullscreen mode |
abstract boolean |
isMouseGrabbed()
Check if the mouse cursor is current grabbed. |
boolean |
isMusicOn()
Check if music is enabled |
boolean |
isPaused()
Check if the container is currently paused. |
boolean |
isShowingFPS()
Check if the FPS is currently showing |
boolean |
isSoundOn()
Check if sound effects are enabled |
boolean |
isUpdatingOnlyWhenVisible()
Check if this game is only updating when visible to the user (default = true) |
boolean |
isVSyncRequested()
True if vsync is requested |
void |
pause()
Pause the game - i.e. |
void |
reinit()
Renitialise the game and the context in which it's being rendered |
void |
resume()
Resumt the game - i.e. |
protected boolean |
running()
True if the game is running |
void |
setAlwaysRender(boolean alwaysRender)
Indicate whether we want this container to render when it has focus |
void |
setAnimatedMouseCursor(java.lang.String ref,
int x,
int y,
int width,
int height,
int[] cursorDelays)
Get a cursor based on a image reference on the classpath. |
void |
setClearEachFrame(boolean clear)
Indicate if we should clear the screen at the beginning of each frame. |
void |
setDefaultFont(Font font)
Set the default font that will be intialised in the graphics held in this container |
abstract void |
setDefaultMouseCursor()
Set the default mouse cursor - i.e. |
void |
setForceExit(boolean forceExit)
Indicate if we should force exitting the VM at the end of the game (default = true) |
void |
setFullscreen(boolean fullscreen)
Indicate whether we want to be in fullscreen mode. |
abstract void |
setIcon(java.lang.String ref)
Set the icon to be displayed if possible in this type of container |
abstract void |
setIcons(java.lang.String[] refs)
Set the icons to be used for this application. |
void |
setMaximumLogicUpdateInterval(int interval)
Set the maximum amount of time in milliseconds that can passed into the update method. |
void |
setMinimumLogicUpdateInterval(int interval)
Set the minimum amount of time in milliseonds that has to pass before update() is called on the container game. |
abstract void |
setMouseCursor(org.lwjgl.input.Cursor cursor,
int hotSpotX,
int hotSpotY)
Set the mouse cursor to be displayed - this is a hardware cursor and hence shouldn't have any impact on FPS. |
abstract void |
setMouseCursor(ImageData data,
int hotSpotX,
int hotSpotY)
Set the mouse cursor to be displayed - this is a hardware cursor and hence shouldn't have any impact on FPS. |
abstract void |
setMouseCursor(Image image,
int hotSpotX,
int hotSpotY)
Set the mouse cursor based on the contents of the image. |
abstract void |
setMouseCursor(java.lang.String ref,
int hotSpotX,
int hotSpotY)
Set the mouse cursor to be displayed - this is a hardware cursor and hence shouldn't have any impact on FPS. |
abstract void |
setMouseGrabbed(boolean grabbed)
Indicate whether mouse cursor should be grabbed or not |
void |
setMultiSample(int samples)
Indicate whether we want to try to use fullscreen multisampling. |
void |
setMusicOn(boolean on)
Indicate whether music should be enabled |
void |
setMusicVolume(float volume)
Set the default volume for music |
void |
setPaused(boolean paused)
Indicates if the game should be paused, i.e. |
void |
setShowFPS(boolean show)
Indicate whether the container should show the FPS |
void |
setSmoothDeltas(boolean smoothDeltas)
Indicate if we want to smooth deltas. |
void |
setSoundOn(boolean on)
Indicate whether sound effects should be enabled |
void |
setSoundVolume(float volume)
Set the default volume for sound fx |
void |
setTargetFrameRate(int fps)
Set the target fps we're hoping to get |
void |
setUpdateOnlyWhenVisible(boolean updateOnlyWhenVisible)
Indicate if the display should update only when the game is visible (the default is true) |
void |
setVerbose(boolean verbose)
Inidcate we want verbose logging |
void |
setVSync(boolean vsync)
Indicate whether the display should be synced to the vertical refresh (stops tearing) |
void |
sleep(int milliseconds)
Sleep for a given period |
boolean |
supportsMultiSample()
Check if this hardware can support multi-sampling |
protected void |
updateAndRender(int delta)
Update and render the game |
protected void |
updateFPS()
Updated the FPS counter |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static SGL GL
protected static org.lwjgl.opengl.Drawable SHARED_DRAWABLE
protected long lastFrame
protected long lastFPS
protected int recordedFPS
protected int fps
protected boolean running
protected int width
protected int height
protected Game game
protected Input input
protected int targetFPS
protected long minimumLogicInterval
protected long storedDelta
protected long maximumLogicInterval
protected Game lastGame
protected boolean clearEachFrame
protected boolean paused
protected boolean forceExit
protected boolean vsync
protected boolean smoothDeltas
protected int samples
protected boolean supportsMultiSample
protected boolean alwaysRender
protected static boolean stencil
Constructor Detail |
---|
protected GameContainer(Game game)
game
- The game to be wrappedMethod Detail |
---|
public static void enableStencil()
public void setDefaultFont(Font font)
font
- The font to use as defaultpublic void setMultiSample(int samples)
samples
- The number of samples to attempt (2 is safe)public boolean supportsMultiSample()
public int getSamples()
public void setForceExit(boolean forceExit)
forceExit
- True if we should force the VM exitpublic void setSmoothDeltas(boolean smoothDeltas)
smoothDeltas
- True if we should report smooth deltaspublic boolean isFullscreen()
public float getAspectRatio()
public void setFullscreen(boolean fullscreen) throws SlickException
fullscreen
- True if we want to be in fullscreen mode
SlickException
- Indicates we failed to change the display modepublic static void enableSharedContext() throws SlickException
SlickException
- Indicates a failure to create the shared drawablepublic static org.lwjgl.opengl.Drawable getSharedContext()
public void setClearEachFrame(boolean clear)
clear
- True if the the screen should be cleared each framepublic void reinit() throws SlickException
SlickException
- Indicates a failure rerun initialisation routinespublic void pause()
public void resume()
public boolean isPaused()
public void setPaused(boolean paused)
paused
- True if the game should be pausedpublic boolean getAlwaysRender()
public void setAlwaysRender(boolean alwaysRender)
alwaysRender
- True if this container should render when it has focuspublic static int getBuildVersion()
public Font getDefaultFont()
getDefaultFont
in interface GUIContext
public boolean isSoundOn()
public boolean isMusicOn()
public void setMusicOn(boolean on)
on
- True if music should be enabledpublic void setSoundOn(boolean on)
on
- True if sound effects should be enabledpublic float getMusicVolume()
public float getSoundVolume()
public void setSoundVolume(float volume)
volume
- the new default value for sound fx volumepublic void setMusicVolume(float volume)
volume
- the new default value for music volumepublic abstract int getScreenWidth()
getScreenWidth
in interface GUIContext
public abstract int getScreenHeight()
getScreenHeight
in interface GUIContext
public int getWidth()
getWidth
in interface GUIContext
public int getHeight()
getHeight
in interface GUIContext
public abstract void setIcon(java.lang.String ref) throws SlickException
ref
- The reference to the icon to be displayed
SlickException
- Indicates a failure to load the iconpublic abstract void setIcons(java.lang.String[] refs) throws SlickException
refs
- The reference to the icon to be displayed
SlickException
- Indicates a failure to load the iconpublic long getTime()
getTime
in interface GUIContext
public void sleep(int milliseconds)
milliseconds
- The period to sleep for in millisecondspublic abstract void setMouseCursor(java.lang.String ref, int hotSpotX, int hotSpotY) throws SlickException
setMouseCursor
in interface GUIContext
ref
- The location of the image to be loaded for the cursorhotSpotX
- The x coordinate of the hotspot within the cursor imagehotSpotY
- The y coordinate of the hotspot within the cursor image
SlickException
- Indicates a failure to load the cursor image or create the hardware cursorpublic abstract void setMouseCursor(ImageData data, int hotSpotX, int hotSpotY) throws SlickException
setMouseCursor
in interface GUIContext
data
- The image data from which the cursor can be construtedhotSpotX
- The x coordinate of the hotspot within the cursor imagehotSpotY
- The y coordinate of the hotspot within the cursor image
SlickException
- Indicates a failure to load the cursor image or create the hardware cursorpublic abstract void setMouseCursor(Image image, int hotSpotX, int hotSpotY) throws SlickException
image
- The image to use as the cursorhotSpotX
- The x coordinate of the hotspot within the cursor imagehotSpotY
- The y coordinate of the hotspot within the cursor image
SlickException
- Indicates a failure to load the cursor image or create the hardware cursorpublic abstract void setMouseCursor(org.lwjgl.input.Cursor cursor, int hotSpotX, int hotSpotY) throws SlickException
setMouseCursor
in interface GUIContext
cursor
- The cursor to usehotSpotX
- The x coordinate of the hotspot within the cursor imagehotSpotY
- The y coordinate of the hotspot within the cursor image
SlickException
- Indicates a failure to load the cursor image or create the hardware cursorpublic void setAnimatedMouseCursor(java.lang.String ref, int x, int y, int width, int height, int[] cursorDelays) throws SlickException
ref
- The reference to the image to be loadedx
- The x-coordinate of the cursor hotspot (left -> right)y
- The y-coordinate of the cursor hotspot (bottom -> top)width
- The x width of the cursorheight
- The y height of the cursorcursorDelays
- image delays between changing frames in animation
SlickException
- Indicates a failure to load the image or a failure to create the hardware cursorpublic abstract void setDefaultMouseCursor()
setDefaultMouseCursor
in interface GUIContext
public Input getInput()
getInput
in interface GUIContext
public int getFPS()
public abstract void setMouseGrabbed(boolean grabbed)
grabbed
- True if mouse cursor should be grabbedpublic abstract boolean isMouseGrabbed()
protected int getDelta()
protected void updateFPS()
public void setMinimumLogicUpdateInterval(int interval)
interval
- The minimum interval between logic updatespublic void setMaximumLogicUpdateInterval(int interval)
interval
- The maximum interval between logic updatesprotected void updateAndRender(int delta) throws SlickException
delta
- The change in time since last update and render
SlickException
- Indicates an internal fault to the game.public void setUpdateOnlyWhenVisible(boolean updateOnlyWhenVisible)
updateOnlyWhenVisible
- True if we should updated only when the display is visiblepublic boolean isUpdatingOnlyWhenVisible()
protected void initGL()
protected void initSystem() throws SlickException
SlickException
- Indicates a failure to create a native handlerprotected void enterOrtho()
public void setShowFPS(boolean show)
show
- True if the container should show the FPSpublic boolean isShowingFPS()
public void setTargetFrameRate(int fps)
fps
- The target fps we're hoping to getpublic void setVSync(boolean vsync)
vsync
- True if we want to sync to vertical refreshpublic boolean isVSyncRequested()
protected boolean running()
public void setVerbose(boolean verbose)
verbose
- True if we want verbose logging (INFO and DEBUG)public void exit()
public abstract boolean hasFocus()
public Graphics getGraphics()
protected void enterOrtho(int xsize, int ysize)
xsize
- The size of the panel being usedysize
- The size of the panel being used
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |