At present, the game on the market, whether stand-alone or online, with multi-angle, many types of scenes have been commonplace. Classic such as "Shaft sword 3", the most traditional Chinese wind RPG role play game, the entire game contains 3 categories of scenes: the World (Earth map) scene, specific (city, cave, etc.) scene and combat (round) scene. The elves have different constraints and realization in the movement, the angle of view, the event and so on in each scene; The three national policies are no exception, the game in addition to a section on the RPG scene, when the battle begins, the game will switch to the SLG round battle scene. Therefore, the 2D game to do a variety of game engine architecture must be built in the scene (Scene) as the core of the framework, this also confirms that throughout the tutorial always the only idea: Scene editor let the game development better!
Nonsense to say so much, next I will continue to explain how to achieve the three national policy SLG part of the scene.
How to make a game with multiple scenarios without confusion? This is one of the most important issues that we have to tackle. My idea is to create an enumeration:
/// <summary>
/// 场景类型
/// </summary>
public enum SceneKinds {
RPG = 0,
SLG = 1,
……
}
Implement different logic through a switch when you need to sort by scene. At this point a friend will certainly ask: this is not an increase in the game framework of the coupling degree? In fact, in terms of performance, even if the scene type has more than 10, the switch consumes almost negligible; In addition, through my own experience, in addition to the game window (Window.cs) there will be some of the scene type enumeration judgment, other places almost will not be used, This is actually the benefit of putting all the objects in the window to interact, and it proves the correctness of the game framework design that I introduced to you in the first few sections, based on the scene (Scene) as the core, Windows (window) as the carrier.
The next step is to add the SLG battle scene node parameters for Scene.xml. Similarly, we open the scene editor, set the coordinate system offset and draw different terrain, by clicking "Export scene Information" to get the new scene of the XML information, this section demo I will be the Code (code) set to 100 to distinguish between the RPG type scene: