public class GameContainer
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected boolean |
alphaSupport
Alpha background supported
|
protected boolean |
forceExit
True if we should force exit
|
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 long |
lastFrame
The time the last frame was rendered
|
protected org.lwjgl.opengl.DisplayMode |
originalDisplayMode
The original display mode before we tampered with things
|
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 |
supportsMultiSample
True if this context supports multisample
|
protected org.lwjgl.opengl.DisplayMode |
targetDisplayMode
The display mode we're going to try and use
|
protected int |
width
The width of the display
|
Constructor and Description |
---|
GameContainer(Game game)
Create a new container wrapping a game
|
Modifier and Type | Method and Description |
---|---|
void |
destroy()
Destroy the app game container
|
static void |
enableSharedContext()
Enable shared OpenGL context.
|
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
|
protected void |
gameLoop()
Strategy for overloading game loop context handling
|
float |
getAspectRatio()
Get the aspect ratio of the screen
|
Font |
getDefaultFont()
Get the default system font
|
protected int |
getDelta()
Retrieve the time taken to render the last frame, i.e.
|
Graphics |
getGraphics()
Get the graphics context used by this container.
|
int |
getHeight()
Get the height of the game canvas
|
int |
getSamples()
The number of samples we're attempting to performing using hardware
multisampling
|
int |
getScreenHeight()
Get the height of the standard screen resolution
|
int |
getScreenWidth()
Get the width of the standard screen resolution
|
static org.lwjgl.opengl.Drawable |
getSharedContext()
Get the context shared by all containers
|
long |
getTime()
Get the accurate system time
|
int |
getWidth()
Get the width of the game canvas
|
boolean |
hasFocus() |
protected void |
initGL()
Initialise the GL context
|
protected void |
initSystem()
Initialise the system components, OpenGL and OpenAL.
|
boolean |
isMouseGrabbed() |
protected boolean |
running()
True if the game is running
|
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 |
setDefaultFont(Font font)
Set the default font that will be intialised in the graphics held in this
container
|
void |
setDefaultMouseCursor()
Set the default mouse cursor - i.e.
|
void |
setDisplayMode(org.lwjgl.opengl.DisplayMode mode,
boolean fullscreen)
Set the display mode to be used
|
void |
setForceExit(boolean forceExit)
Indicate if we should force exitting the VM at the end of the game
(default = true)
|
void |
setIcon(java.lang.String ref) |
void |
setIcons(java.lang.String[] refs) |
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.
|
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.
|
void |
setMouseCursor(Image image,
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.
|
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.
|
void |
setMouseGrabbed(boolean grabbed) |
void |
setMultiSample(int samples)
Indicate whether we want to try to use fullscreen multisampling.
|
void |
setTitle(java.lang.String title)
Set the title of the window
|
protected void |
setup()
Setup the environment
|
void |
setVerbose(boolean verbose)
Inidcate we want verbose logging
|
void |
start()
Start running the game
|
boolean |
supportsAlphaInBackBuffer()
Check if the display created supported alpha in the back buffer
|
boolean |
supportsMultiSample()
Check if this hardware can support multi-sampling
|
protected org.lwjgl.opengl.DisplayMode originalDisplayMode
protected org.lwjgl.opengl.DisplayMode targetDisplayMode
protected boolean alphaSupport
protected static SGL GL
protected static org.lwjgl.opengl.Drawable SHARED_DRAWABLE
protected long lastFrame
protected boolean running
protected int width
protected int height
protected Game game
protected boolean forceExit
protected int samples
protected boolean supportsMultiSample
public GameContainer(Game game) throws SlickException
game
- The game to be wrappedSlickException
- Indicates a failure to initialise the displaypublic 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 float getAspectRatio()
public static void enableSharedContext() throws SlickException
SlickException
- Indicates a failure to create the shared drawablepublic static org.lwjgl.opengl.Drawable getSharedContext()
public Font getDefaultFont()
public int getWidth()
public int getHeight()
public long getTime()
public 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 to right)y
- The y-coordinate of the cursor hotspot (bottom to top)width
- The x width of the cursorheight
- The y height of the cursorcursorDelays
- image delays between changing frames in animationSlickException
- Indicates a failure to load the image or a failure
to create the hardware cursorprotected int getDelta()
protected void initGL()
protected void initSystem() throws SlickException
SlickException
- Indicates a failure to create a native handlerprotected void enterOrtho()
protected boolean running()
public void setVerbose(boolean verbose)
verbose
- True if we want verbose logging (INFO and DEBUG)public void exit()
public Graphics getGraphics()
protected void enterOrtho(int xsize, int ysize)
xsize
- The size of the panel being usedysize
- The size of the panel being usedpublic boolean supportsAlphaInBackBuffer()
public void setTitle(java.lang.String title)
title
- The title to set on the windowpublic void setDisplayMode(org.lwjgl.opengl.DisplayMode mode, boolean fullscreen) throws SlickException
mode
- The DisplayMode to be usedfullscreen
- True if we want fullscreen modeSlickException
- Indicates a failure to initialise the displaypublic void setMouseCursor(java.lang.String ref, int hotSpotX, int hotSpotY) throws SlickException
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 imageSlickException
- Indicates a failure to load the cursor image or create the hardware cursorpublic void setMouseCursor(ImageData data, int hotSpotX, int hotSpotY) throws SlickException
data
- The image data from which the cursor can be constructedhotSpotX
- The x coordinate of the hotspot within the cursor imagehotSpotY
- The y coordinate of the hotspot within the cursor imageSlickException
- Indicates a failure to load the cursor image or create the hardware cursorpublic void setMouseCursor(org.lwjgl.input.Cursor cursor, int hotSpotX, int hotSpotY) throws SlickException
cursor
- The cursor to usehotSpotX
- The x coordinate of the hotspot within the cursor imagehotSpotY
- The y coordinate of the hotspot within the cursor imageSlickException
- Indicates a failure to load the cursor image or create the hardware cursorpublic void setMouseCursor(Image image, int hotSpotX, int hotSpotY) throws SlickException
image
- The image from which the cursor can be constructedhotSpotX
- The x coordinate of the hotspot within the cursor imagehotSpotY
- The y coordinate of the hotspot within the cursor imageSlickException
- Indicates a failure to load the cursor image or create the hardware cursorpublic void start() throws SlickException
SlickException
- Indicates a failure to initialise the systemprotected void setup() throws SlickException
SlickException
- Indicates a failureprotected void gameLoop()
public void setIcon(java.lang.String ref) throws SlickException
SlickException
public void setMouseGrabbed(boolean grabbed)
public boolean isMouseGrabbed()
public boolean hasFocus()
public int getScreenHeight()
public int getScreenWidth()
public void destroy()
public void setIcons(java.lang.String[] refs) throws SlickException
SlickException
public void setDefaultMouseCursor()