Yann - that's a great screenshot, and shows the truly ingenious levels of sprite re-use that professional games use, and you hardly notice unless you look carefully. Construct 2 makes this convenient too since you can take a sprite and scale it, rotate it and copy to different layers. I think even the original Mario got away with using the cloud image for bushes, but with a different palette to change the color to green. So there's a long history of this kind of trickery!
Arima - the memory manager only works layout-by-layout - it currently makes no effort to release textures mid-game. It will only release anything when changing layout. It tries to pre-load everything on a layout when the layout starts, but it does this by looking at which objects are placed in the layout view initially. If you create an object not initially in the layout view, it still has to load the texture at the moment you create it, which can create a pause.
Modern 3D games use a technique called texture streaming, which is where they load and unload textures dynamically as you move around. However they have two advantages in doing this:
- they support threaded texture loading, so they can load textures to the GPU in the background without pausing the game. WebGL doesn't support this yet, although I think the group working on it want to add support using Web Workers or similar.
- they are 3D, which means they exploit distance. If a texture has not been loaded, the object will appear a solid colour. However it will generally load textures as you approach objects from a distance. So at first they are usually so small in the distance you can't see any texture detail. The texture usually gets loaded before you can approach and see any detail, meaning it's a pretty seamless experience. In 2D, there is no distance, so objects will simply appear as holes in the level until they get streamed in. This makes it more difficult to ensure textures are always loaded by the time you scroll to them - especially difficult if you can scroll very quickly in unpredictable directions.
So we could improve texture streaming capabilities in C2, but the tech isn't quite there yet, and it would still be hard to use. I'd still recommend taking the composition approach (Rayman style). Not only does it make the game use a lot less memory, it also makes the download size considerably smaller, which is especially important for web games.