Thursday 4 April 2013

GameAsset and GameSetting!


Every game needs two basic features, resource management and storage set and setting.

Game Asset

You already know that game asset is an indispensable component in method initializeGameService () of the Game class, what exactly is the function of the Game Asset?
Asset will manage all the resource in your game. resource is the resource that you use such as texture, texture region to render object2D or covered up a Model3D. Sound and Music to create sound effects, bitmap font used to draw text to the screen, shader to render object3D ... Asset load resource management also dispose resource. Asset provides utility methods to load the resource is quick and convenient. every game asset inherited from class BaseGameAsset, Engine has a class that implements the standard is DefaultGameAsset.
Every resource should be load when you start the game and should be freed when exit game. Sourcing resource (asset), use resource for game object and dispose resource is done in Game Asset. Years DefaultGameAsset has implement IGameAsset interface and provides methods function to load the texture, load the texture region, load music, load bitmap font resource load ... The whole process should be done in the load () method of GameAsset. dispose process should be done in the dispose (). DefaultGameAsset a boolean isLoaded (Default: false) signaling game resource load all or not:
For example:
/ / Declaration
public static Texture BGTexture;
@ Override
       public void load ()
             
              {if(isLoaded)
                     return;
             
              BGTexture = loadTexture("spacewar/bg.png",Format.RGBA4444, true);
/ / Load for more resource ...
              isLoaded = true;}
      
@ Override
       public void dispose ()
              {BGTexture.dispose()
              {// Dispose for more
       resource}
Load () method is called when you initilize Game-services and dispose () method is called when exit game. Engine will call this method for you.

GameSetting

This class is responsible for create, load, modify and save your settings in the game, including the game data of the user that you want to save. Every Game setting legacy inherited from class BaseGameSetting, Engine has a class that implements the standard is DefaultGameSetting.
Method loadSetting () will be called automatically when you call method initializeGameServices () to load the setting of the game when you start the game. Method saveSetting () will be called when your game is Paused or before exit game. It will save the setting for the next time you start Games.
ModifySetting (int key, Object value) method and getSetting (int key) is an abstract method, no part implements standard so you will have to write them in the extended class if they wish to use this method. You can see an example in [this]
class DefaultGameSetting implements the method for the save and load data under as Data Serializabled. You can create a class GameData contains the value to be stored in hardware devices, GameData implements theinterface Serializable in thepackage. java.iothen you can use methods loadSetting (Class) and saveSetting (Serializable) ofDefaultGameSetting to create new, load or save GameData very easily. Static variable 'savefile' of DefaultGameSetting will name specified save file saved on the device's hardware.
Example:
DefaultGameSetting.file = ".spacewardata";
              BaseGameSetting baseGameSetting = new DefaultGameSetting();
              gameData = baseGameSetting.loadSetting(GameData.class);
              if(gameData == null)
              {
                     gameData = new GameData();
                     baseGameSetting.saveSetting(gameData);
              }
             
the specified code name save file is '. spacewardata' and if load gameData is null (When you first start the game, the game can not save file, loadSetting () method returns null), the game will automatically create save file is '. spacewardata' default and save the data in the GameData class file on hardware device, by use saveSetting ()method.

Not only Serializable game data is supported, the object interface Externalizable Data will supported similar methods loadSetting (Externalizable) and saveSetting (Externalizable).

No comments:

Post a Comment