Hi
I have built a framework that can handle just about “anything”. It’s so simple as it can get, with only two core framework classes.
CoreFrame - Is the frame where the game is being rendered. Handles switching to fullscreen, windowmode, input and the rendering loop with timing. Holds information about the size of the frame, if the rendering is started, fps count etc.
CoreEntity - A simple “thing” that lives withing the game. Can be a sprite, scene, a layer within a scene etc etc. CoreEntity is only an interface with four method, init(), tick(), display() and destroy(). When creating a new entity you just implement these methods and extends with the entity specific methods.
The thing is that CoreFrame can only render one CoreEntity, that is within the rendering loop if an CoreEntity has been set on the CoreFrame its tick methods is first called to update the entity followed by the display method.
So what about handling multiple scenes? Just create a new entity that implements CoreEntity and name it Scene. A scene should of course be able to handle rendering more than one entity so some sort of collection to hold the entities within the scene i nessessery. So in the display method of the scene just loop through the collection and call every entities display() method. The same with the other method. Set the scene on the CoreFrame, as it is an CoreEntity this i allowed. And when it is time to switch between scenes just exhange the current rendering entity in the CoreFrame with the new scene.
Why entities? Take the example of a large levelboss. It contains of many sprites, eyes moving, moving legs etc. If your rendering framework only can render sprites you have no logic way to connect the sprites with each other. But if you create a EndLevelEntity that contains all the sprites(that also are entities) you can only call the display() and it’s EndLevelEntities responsibility to draw all sprites that the boss contains of.
I have extended the framework with the following classes for the moment.
Scene - As explained abow
Layer - If you need to control which entites that are rendered on top of others use a layer to group them and add it to the current scene.
Sprite - No explaination needed
All these classes implements CoreEntity.
Also I have a collision framework that work out collision between entites.
I have build a number of small rendering framework before and have always overbuilt them. Thats why I like this simple approch. Maybe it is something for you to?
Edit: typos