Now lets talk about game/live wallpaper structure/logic that can be built with LibGDX Scene2D. As you know Scene2D consists of Stage/Group/Actors. By using Mtx, I have created objects which extends these Scene2D elements with very useful features. (AbstractScreen, AbstractWorldScene2D, AbstractActor)
I want my screen is to be start of everything, at the same time I do not give direct responsibility to my screen, thus gameManager is responsible for creating and managing the world. A little bit Cohesion/Coupling of object oriented programming.
Screen (extends AbstractScreen of Mtx) - constructing Scene2D Stage
World and WorldLayers (extends AbstractWorldScene2D) - Scene2D Groups
Rest of objects are Scene2D Actors (extends AbstractActors)
SCREEN (ABSTRACTSCREEN)
As you can see, I only construct the gameManager and gameScreenMenu classes in my screen, this is all responsibility of the screen. gameScreenMenu is for creating menu buttons and etc. (For example, play/stop button).
INTERFACES
You may notice that I implemented IScreen and IGameScreen interfaces, I love interfaces. Because, everytime I start a project, I do not need to think about structure or common methods that being used such as "setUpMenu()", so by using interfaces, in a single second, I will know what to do
GAMEMANAGER
GameManager is responsible of world and world layers and game state (I will talk about in later tutorials), So I create the main world (Scene2D Group) and add world layers to that world. It may sound like worlds in a main world. (Scene2D Groups being added to a single Scene2D Group)
At the end I add to main world to Scene2D Stage.
TO SUM UP
The sructure goes like this;
- Screen creates the stage
- Screen constructs the GameManager and pass stage to GameManager
- GameManager creates the Main World (Scene2D Group) and adds WorldLayers (Scene2D Groups)
- Each world layer has different Scene2D Actors due to their purposes (Clouds, Snows, Emeny objects, etc...)
IGameManager
Again an interface that helps me alot
public void setUpWorld();
public void startLevel(int levelNumber);
public void checkGameCondition();
public void update(float delta);
public void saveGame();
public void exitGame();
In each project of mine, I mostly use the methods above, so why not store them in an interface, and easily use it. This is a good practice for your programming skills, saves time and increases efficiency. Furthermore, I can improve it in time.
Hi. Nice tutorial, but actually i'm still facing with design issues. My actors like enemies or the elements controlled by the player have hp. When they die (hp == 0) their removes themselves from the Stage. I would need to increment the Player's score when he kills an enemy, but i don't know where i should store the game data (score, money ecc..) and how to update the HUD consequently.
ReplyDelete