public abstract class Sequence extends Object
Keyboard
, Mouse
), and it includes a
standard game loop (update(double)
and render(Graphic)
), synchronized to a
specified frame rate.
Here a blank sequence implementation:
final class Scene extends Sequence { private static final Resolution NATIVE = new Resolution(320, 240, 60); Scene(Loader loader) { super(loader, Scene.NATIVE); } @Override protected void load() { // Load } @Override protected void update(double extrp) { if (keyboard.isPressed(Key.ESCAPE)) { end(); } // Update } @Override protected void render(Graphic g) { // Render } }
Loader
,
Resolution
,
Graphic
Modifier and Type | Field and Description |
---|---|
protected int |
height
Screen height.
|
protected Keyboard |
keyboard
Keyboard reference.
|
protected Loader |
loader
Loader reference.
|
protected Mouse |
mouse
Mouse reference.
|
protected Resolution |
source
Source resolution reference.
|
protected int |
width
Screen width.
|
Constructor and Description |
---|
Sequence(Loader loader,
Resolution resolution)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addKeyListener(KeyboardListener listener)
Add a key listener.
|
protected void |
clearScreen(Graphic g)
Clear the screen.
|
void |
end()
Terminate sequence, close screen, and start launcher if exists.
|
void |
end(Sequence nextSequence)
Terminate sequence, and set the next sequence.
|
Config |
getConfig()
Get the configuration.
|
int |
getFps()
Get current frame rate (number of image per second).
|
Keyboard |
getKeyboard()
Get the keyboard reference.
|
Mouse |
getMouse()
Get the mouse reference.
|
protected abstract void |
load()
Loading sequence data.
|
protected void |
onFocusGained()
Called when sequence is focused (screen).
|
protected void |
onLoaded(double extrp,
Graphic g)
Called when the sequence has been loaded.
|
protected void |
onLostFocus()
Called when sequence lost focus (screen).
|
protected void |
onResolutionChanged(int width,
int height,
int rate)
Called when the resolution changed.
|
protected void |
onTerminate(boolean hasNextSequence)
Called when sequence is closing.
|
protected abstract void |
render(Graphic g)
Render sequence.
|
void |
setExtrapolated(boolean extrapolated)
Set the extrapolation flag.
|
void |
setMouseVisible(boolean visible)
Set the mouse visibility.
|
protected void |
setResolution(Resolution newSource)
Set the new resolution used by the sequence.
|
void |
start(Sequence nextSequence,
boolean wait)
Start the next sequence, call the
load() function, and wait for current sequence to end before next
sequence continues. |
protected abstract void |
update(double extrp)
Update sequence.
|
protected final Keyboard keyboard
protected final Mouse mouse
protected final Loader loader
protected Resolution source
protected int width
protected int height
public Sequence(Loader loader, Resolution resolution)
loader
- The loader reference.resolution
- The resolution source reference.protected final void setResolution(Resolution newSource)
newSource
- The new resolution used.protected abstract void load()
protected abstract void update(double extrp)
extrp
- The extrapolation value. Can be used to have an non dependent machine speed calculation. Example: x
+= 5.0 * extrpprotected abstract void render(Graphic g)
g
- The graphic output.public final void end()
public final void end(Sequence nextSequence)
nextSequence
- The next sequence reference.public final void start(Sequence nextSequence, boolean wait)
load()
function, and wait for current sequence to end before next
sequence continues. This function should be used to synchronize two sequences (eg: load a next sequence while
being in a menu). Do not forget to call end()
in order to give control to the next sequence. The next
sequence should override onLoaded(double, Graphic)
for special load just before enter in the loop.nextSequence
- The next sequence reference (must not be null
).wait
- true
to wait for the next sequence to be loaded, false
else.public final void addKeyListener(KeyboardListener listener)
listener
- The listener to add.public final void setMouseVisible(boolean visible)
visible
- The visibility state.public final void setExtrapolated(boolean extrapolated)
extrapolated
- true
will activate it, false
will disable it.public final int getFps()
public Config getConfig()
public Keyboard getKeyboard()
public Mouse getMouse()
protected final void clearScreen(Graphic g)
g
- The graphics output.protected void onLoaded(double extrp, Graphic g)
extrp
- The extrapolation value.g
- The graphic output.protected void onResolutionChanged(int width, int height, int rate)
width
- The new screen width.height
- The new screen height.rate
- The new rate.protected void onTerminate(boolean hasNextSequence)
start(Sequence, boolean)
has been used by another sequence. Does nothing by default.hasNextSequence
- true
if there is a next sequence, false
else (then application
will end definitely).protected void onFocusGained()
protected void onLostFocus()
Copyright © 2014 Byron 3D Games Studio. All rights reserved.