Base tools are provided by the lionengine-game
module, giving a balanced game type development with
standard classes and architecture. It is also the main dependency of any other game specialized module.
In this section we will see how to use these main tools, and the way of we should use them.
Primary objects where designed to be your game socle, allowing to count on a solid base.
Featurable
This is the main primary object type, providing essential tools for any complex object. It is designed to work with:
Setup
, can be used as a constructor parameterUsing this class will allow to benefit from
Feature
system.Each object is represented by an XML configuration file, allowing external configuration.
Setup
This class represents the configuration base from an XML file, usually used for
ObjectGame
. The class's goal is to share resources between objects, in order to reduce memory usage (as a sprite for example).
Services
This is the focal point when talking about dependencies handling. Any object will sooner or later need to access to external services (such as
Camera
or gameMapTile
).It is so possible to access to external declared services since object construction. Due to weak type checking, it is highly recommended to ensure that services are correctly added, any error will lead to an exception during execution when a mis added service will be requested. Think to document well your objects class in order to not forget to add the right service !
It is recommended to declare services as follow:
1 2 3 4 | private final Services services = new Services(); private final Factory factory = services.create(Factory. class ); private final Camera camera = services.create(Camera. class ); private final MapTile map = services.create(MapTileGame. class ); |
Services will be created and automatically added to the container in order to be used externally.
Camera
It is a common used class, as it represents what you see on the world you created. This will probably be one of your first service...
Cursor
This class will allow to handle system pointer in a customized way, sync or async to system one, plus with customized pointer images.
The Factory
allows to create typed ObjectGame
using a generic way.
It is now possible to create type instances, without doing any cast. Just ensure that you use the same type as the class target type. Else you will have an error during the creation.
The Handler
allows to handle many objects, in order to update and render them. It is possible to
add and remove objects while using the handler. Changes will be performed at the end of the handler update.
You can now update a series of object, and render them. New objects can be added at any time.
The WorldGame
is used as the main game container, rather than the Sequence
, as it supports
save and load features. The main goal of a world is to handle the game logic update and render order. With such a
class, the Sequence
is only used to load a WorldGame
, update and render it, nothing more.
To show all the main features, the world will just save a simple string, and load it. It will also display on screen the loaded string.
The only object handled by the scene is the world, calling save and load just to show how it is working.
As you can see, this is very basic. But once you will add more things in your world (such as Map
, Handler
...),
it will be easy to define a game saving and loading, as each complex object can be saved easily (MapTile
already have save and load functions). You can also implement different version of a world, and just select it from
the Sequence
, without changing any other thing.
Read next page: Network Games