public abstract class WorldGame extends Object implements Updatable, Renderable
Factory
, Handler
...).
It contains the following configured fields:
Config
: The configuration used by the Loader
width
: The source screen width, retrieve from the source screen Resolution
height
: The source screen height, retrieve from the source screen Resolution
Services
: Pre-configured instance with the following added services:
Camera
: Configured with screen size as viewHandler
: Shipped with ComponentRefreshable
and ComponentDisplayable
Factory
: Listener added with Handler.addListener(HandlerListener)
It has to be handled by a Sequence
. Here a standard world usage:
public class MySequence extends Sequence { private final World world; public MySequence(Context context) { super(loader); // Initialize variables here world = new World(context); } @Override public void load() { // Load resources here world.loadFromFile(Media.get("level.lvl")); } @Override public void update(double extrp) { // Update routine world.update(extrp); } @Override public void render(Graphic g) { // Render routine world.render(g); } }
Modifier and Type | Field and Description |
---|---|
protected Camera |
camera
Camera instance (Configured with screen size as view).
|
protected Config |
config
Config reference.
|
protected Context |
context
Context reference.
|
protected Factory |
factory
Factory instance.
|
protected Handler |
handler
Handler instance (configured with
ComponentRefreshable and ComponentDisplayable ). |
protected Resolution |
output
External display reference.
|
protected Services |
services
Services instance.
|
protected Resolution |
source
Internal display reference.
|
Constructor and Description |
---|
WorldGame(Context context)
Create a new world.
|
WorldGame(Context context,
Services services)
Create a new world.
|
Modifier and Type | Method and Description |
---|---|
void |
fill(Graphic g,
ColorRgba color)
Fill with color.
|
<T extends InputDevice> |
getInputDevice(Class<T> type)
Get the input device instance from its type.
|
void |
loadFromFile(Media media)
Load world from the specified file.
|
protected abstract void |
loading(FileReading file)
Internal world loads; called from
loadFromFile(Media) function. |
void |
onResolutionChanged(int width,
int height,
int rate)
Called when the resolution changed.
|
void |
render(Graphic g)
By default, renders handler.
|
void |
saveToFile(Media media)
Save world to the specified file.
|
protected abstract void |
saving(FileWriting file)
Internal world saves; called from
saveToFile(Media) function. |
void |
update(double extrp)
By default, updates handler.
|
protected final Services services
protected final Camera camera
protected final Factory factory
protected final Handler handler
ComponentRefreshable
and ComponentDisplayable
).protected final Config config
protected final Resolution source
protected final Resolution output
protected final Context context
public WorldGame(Context context)
Config
,
screen size and wide state.context
- The context reference.protected abstract void saving(FileWriting file) throws IOException
saveToFile(Media)
function. The world will be saved in a file
as binary. Here should be called all saving functions, such as
Persistable.save(FileWriting)
...file
- The file writer reference.IOException
- If error on writing.protected abstract void loading(FileReading file) throws IOException
loadFromFile(Media)
function. The world will be loaded from
an existing binary file. Here should be called all loading functions, such as
Persistable.load(FileReading)
...file
- The file reader reference.IOException
- If error on reading.public final void saveToFile(Media media)
media
- The output media.LionEngineException
- If error on saving to file.public final void loadFromFile(Media media)
media
- The input media.LionEngineException
- If error on loading from file.public void fill(Graphic g, ColorRgba color)
g
- The graphic output.color
- The color to fill with.public final <T extends InputDevice> T getInputDevice(Class<T> type)
T
- The input device.type
- The input device type.LionEngineException
- If device not found.public void onResolutionChanged(int width, int height, int rate)
width
- The new screen width.height
- The new screen height.rate
- The new rate.public void update(double extrp)
public void render(Graphic g)
render
in interface Renderable
Copyright © 2017 Byron 3D Games Studio. All rights reserved.