Hello, colleagues! I want to share my developments and wishes. Initially, I was uncomfortable when I tried to use only the Monogame component system (IGameComponent in Game.Conmponents). But when I tried the popular C# game engine (I won’t say the name), I was attracted to the game object management system. I tried to recreate a similar system, but with my own facilities. The result is a SceneGraph project of containers with components.
ZZZ.Framework Hyperlink to Github project:
- Objects with components and child objects.
- Automatic start and shutdown of components.
- Functions and methods for adding/removing/receiving components and child objects.
- Automatic addition of related components (for example, the SpriteRenderer sprite drawing component is linked to the Transformer positioning component. The Transformer component will be automatically added along with SpriteRenderer if it is missing).
- A system of registrars. For example, if you create an UpdaterRegistrar~IGameComponent~ logger and add it to the SceneGraph root, it will automatically receive every IGameComponent added to any container on the scene. Registrars make it possible to fill in data and monitor components. For example, UpdaterRegistrar~IGameComponent~ will call the Update(GameTime) method from IGameComponent.
After creating ZZZ.Framework, I used it in conjunction with Monogame. This resulted in several 2D projects:
- Transforming: 2D positioning by vector, scaling and rotation. The Transformer component is the main component of each container. I will highlight from the advantage that Transformer automatically creates a new position if its parent container has changed its position. It is possible to translate from local to world coordinates, and vice versa.
- Rendering: Draws each renderComponent depending on the RenderLayer layer. The advantage is that one component can be drawn on multiple layers. The same applies to the Camera component (the camera displays certain layers). The base component renderComponent is the basis for creating other drawable components (for example, SpriteRenderer, TextRender and TilemapRenderer).
- FarseerPhysics: The FarseerPhysics project is connected to the project and Rigidbody and Collider components are created. The rigid body and the collider can work in conjunction or not. Of the minuses, I will add that I could not link Collider with child Colliders…
- Tiling: A simple tile system. There are static, animated and managed tiles (the managed tile changes itself depending on the neighboring tile). There are also physical colliders for each tile. Downloading from a file .tmx is not supported yet.
- Animating: A system for animating sprites, depending on the values of the parameters in the AnimatorController. The controller has stages and conditions for which the animation of the object is played. There is also synchronization of one AnimatorController for other objects (for example, the animation of the legs is played together with the animation of the body, although there is only one AnimatorController).
- Auding: sound and music components. Sound components can change their volume and balance depending on the position of the listener. The music component can play a playlist with music.
- Asseting: There is an AssetManager that can create copies of objects, save to XML and upload content files. With proper use and compliance with the rules of object serialization, you can save the entire scene to an XML file and upload it back. Note that in XML files, media files will only have a path to the physical file. And if the media file was not downloaded from the file, then it will be fully serialized into an XML file).
The writing code is like a beginner’s. Somewhere in the project there are crutch solutions, but they are temporary.
The projects described above are wrappers of Monogame classes. This makes it possible for cross-platform development.
Actually, in this post I wanted to find like-minded people and critics. Perhaps some people will like this idea and they will create their own components and use them in other projects (not only in Monogame). Maybe someone will criticize this project and write a worthy criticism.
Still, for those who are interested in the idea, I can prepare a video and demonstrate the functionality of the project.