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 practice? Having multiple canvas to draw? Each game loop 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 every time 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...