(No. 00005) iOS pop-up games (4): Game data initialization (1)
In the previous article, we initially looked at the initialization methods of the MainScene class, where the Randomization map was done in the initGameDataFromGD method. Let's take a closer look at this method.
This method is a long method, which calls several other methods. I will list the main code below:
// Use game data to initialize the data of the current level-(void) initGameDataFromGD {[_ gd loadGameData]; // omitting a lot of code _ player that initializes the TAG content of the HUD layer. canw.ssbrick = _ gd. canplayerjavasssbrick; _ player. canw.ssbomb = _ gd. canPlayerAcorssBomb; _ isPlayerSpeedUp = _ gd. isPlayerSpeedUp; if (_ isPlayerSpeedUp) {_ player. speedPerStep = 0.4;} [self updateStateLabel]; _ totalSec = _ gd. curLevelLeftTime; [_ hudLayer updateTimeLabel: _ totalSec]; [self initNoWallTiles]; // random map method [self randomCreateMap]; [self initWalkableTiles]; // initialize the names of all FS classes [FireSprite initClassNames]; [self spawnFireSprites3];}
This method is more "Miscellaneous". It mainly does the following:
Read the data stored in the iOS device to the memory so that the record and content of each play can be saved and reloaded. This is done in the loadGameData method, next we will introduce how to set the corresponding tags in the HUD Layer Based on Game data. The HUD is the dashboard in our game:
The tags include the remaining lifetime, bomb count, current Accumulated Score, power of current bomb, remaining time of the game, and so on. The following is displayed in the actual game:
The vertical bar on the far left is actually displayed outside the visible range of the screen. If necessary, it will pop in. No need to worry about it here.
Based on Game data, set the attributes of the game's main character: whether the game can wear walls and bombs, whether the status labels in the HUD can be updated at high speed, and the updateStateLabel method is called, we will refer to the subsequent initialization of all the tile coordinates that can be laid out. The call method is the initNoWallTiles method and then the randomCreateMap method to create a random map. Don't worry about initializing all the reachable tiles immediately, the call method is the initWalkableTiles method. Initialize all class names in the FireSprite enemy class and generate "Enemies" based on the data in the level. The spawnFireSprites3 method is called.