In general, cocos2d-x is a good library.
Cocos2d-x doesn't have a very complex architecture, basically some managers provided in a single form and some classes that expand around SceneGraphCCNode and Its Derived classes. This design makes the cocos2d structure concise and easy to use.
At the same time, cocos2d designers make full use of some ready-made game development tools to integrate these tools into the engine, such as BMFont, TexturePacker and other tools, making material production very convenient.
As a cross-platform game library, cocos2d-x has done very well. But if I position cocos2d-x as a cross-platform gaming engine, I think Cocos2d-wants to develop in the following areas:
1,Cocos2d-x can provide a good gaming framework:
Some Demo provided by the cocos2d-x, as well as the method to teach people to write programs is basically to let developers write a CCScene subclass, through the way of subclass to achieve specific logic, as teaching is very good.
As a formal developer, I personally suggest that the cocos2d-x can provide a specific game framework that provides a general function of a mobile platform game in general, such as LoadingScene, TitleScene, HighscoreScene, and so on ), game Developers only need to choose to customize their own games based on their own game situations.
2,Cocos2d-x's support for game logic can be enhanced:
For the development of this, how to write the game logic is a troublesome problem, Cocos2d-x with SceneGraph way to manage the scene, it is natural, game Developers certainly want to use the cocos2d-x to provide the way to manage objects, this will be derived from CCNode and other objects, and even some developers also suggest writing functional Code directly from the CCSprite and other omnipotent class derived classes. This method is not impossible, but as a good developer, you will find many problems in the future. For example, after the game is complicated, you will find that there are many hierarchy of inheritance relationships, so that the code needs to be constantly restructured to meet new requirements. Finally, the base classes you designed become more and more complex.
Currently, the mainstream method is to use the Entity-Component system to combine our logic. The Entity-Component system will not be detailed here. An object in the game is an Entity. Each Entity is composed of one or more components.
For example, a plane in the game's lightning game can be Flyable to fly Component to provide the flight function), Shotable can launch Component, provide the function of launching bullets), SpriteSprite Component, provide the display function) and Colliable collision Component, which provides the collision detection function.
Of course, the only Entity-Component system is not enough for the game framework. For example, when a bullet hits a plane, does it directly call a function? Direct calling is certainly not good. First, the bullets and planes are both Entity. from the outside, you don't know what Component they are composed of. You can directly query Component and call the Component function. This obviously violates the encapsulation principle. If the message System Event System is provided and a message is sent to Entity, after the component in Entity receives the message, it is set up to process the message it cares about. This not only implements the function, but also has a beautiful structure.
3,Support of cocos2d-x for game development tools:
For game development engines, excellent tools are always the first. With tools, game developers can quickly create prototypes, and then quickly develop games through iterative optimization of values and performance.
To Cocosbuilder such a tool for it, the current stage of cocos2d-x to do a tool such a function, but also need to improve the code. The most basic is to provide support for persistent Persistence. You can save the game content or the content created in the editor to a disk file at any time. You can open the saved files as needed.
To achieve this, I think there are several basics that need to be added:
1. Provides RTTI support;
- So that an object is running to determine whether it is a certain type of object PS: Don't tell me to use dynamic_cast for implementation .), For specific implementation, refer to many existing solutions;
2. Provide factory-like support;
- You can construct the corresponding class based on the saved class name in the file. For example, when reading "CCNode", you can create a CCNode object based on "CCNode;
3. Set object attributes;
- When reading an attribute name and a value, you can set the attributes of an object in one way. For example, when reading data to osition, you can set node-> setPosition (xxx ).
These are my personal ideas. I hope you can give your own opinions.