We're developing a jump and run game with HTML5 and JavaScript and have to build an own game framework for this. Here we have some difficulties and would like to ask you for some advice:
we have a "Stage" object, which represents the root of our game and is a global div-wrapper.
The stage can contain multiple "Scenes", which are also div-elements. We would implement a Scene for the playing task, for pause, etc. and switch between them.
Each scene can therefore contain multiple "Layers", representing a canvas. These Layer contain "ObjectEntities", which represent images or other shapes like rectangles, etc. Each Objectentity has its own temporaryCanvas, to be able to draw images for one entity, whereas another contains a rectangle.
We set an activeScene in our Stage, so when the game is played, just the active scene is drawn.
Calling activeScene.draw(), calls all sublayers to draw, which draw their entities (calling drawImage(entity.canvas)).
But is this some kind of good practive? Having multiple canvas to draw? Each gameloop every layer-context is cleared and drawn again. E.g. we just have a still Background-Layer, … wouldn't it be more useful to draw this once and not to clear it everytime and redraw it?
Or should we use a global canvas for example in the Stage and just use this canvas to draw? But we thought this would be to expensive...
Other question:
Do you have any advice how we could dive into implementing an own framework? Most stuff we find online relies on existing frameworks or they just implement their game without building a framework.