Docs
Memory and loading
What an animation costs on a phone, how it is counted, how to bring it down, and how to choose your own limit.
Every memory number GreatSprites shows is GPU memory: the space an animation takes on the graphics chip while it is loaded. Your export's weight-report.json lists it per clip, on a phone and on desktop, with the download size and the totals. The price check shows the same figure before an animation is made, and your agent tells you it.
How it is counted
An animation is stored as GPU-compressed frames and a small motion layer that fills in the frames between them. Its memory is the pixel area of those frames times their number:
- Size. The runtime loads the smallest stored size that stays sharp at the height you draw the element at, in device pixels: the height you pass times your renderer's resolution. Twice the height is about four times the memory, which is why size matters more than length.
- Length. More seconds, more frames: a 3 second clip costs about twice a 1.5 second one.
- Reach. Each frame is stored as large as what it shows. A motion that spreads the picture out, a big jump or a wide swing, has larger frames than one that stays inside the picture's outline.
- Device. Phones get a compressed format less than half the size of the desktop one. Plan with the phone figure: the desktop figure is about twice as large, and desktops have far more memory.
Loading an element loads every clip in its folder and keeps them until you release it. Copies of the same element at the same height share one loaded set: fifteen coins cost the memory of one. The same element loaded at two heights is loaded twice.
What counts: what is loaded at the same time
The budget is for the animation loaded at one time, not for every animation your game has. A bonus game can have a set of its own: release the base game's elements before loading the bonus ones, and the other way round when the bonus ends.
// Entering the bonus: free first, then load.
for (const url of baseGameElements) gs.release(url);
const spider = await gs.character('./sprites/bonus-spider/');Release first: loading the bonus before releasing the base game holds both for a moment. Load during a transition, such as the bonus intro, because loading takes a moment: the files come from the browser's cache, but they are prepared for the GPU again. An element on screen in both, a symbol the bonus also uses, stays loaded and counts in both.
How to bring it down
- Load at the height you really draw at. Phones with very sharp screens multiply it: a renderer resolution capped at 2,
resolution: Math.min(devicePixelRatio, 2), often keeps elements in the smaller stored size without a visible difference. - Keep clips short. Every clip ends on the still, so a 1.5 second clip played every few seconds looks alive at half the memory of a 3 second loop.
- Export only the clips you use. Every clip in an element's folder loads with it.
- Use one height per element, so its copies share one set.
- Release what is not on screen: a bonus game, a feature, a menu.
- Load the big, rare ones late. A full-screen win can load just before it plays and be released right after.
Our recommendation, your line
We recommend about 32 MB of GPU memory and 15 MB of animation download on a phone for what is loaded at the same time. In our own games that holds about 25 seconds of animation. It is a starting point, not a limit: the runtime enforces nothing, and every price check shows the animation against the line so you always see where you are.
Why there is a line at all: a phone browser shares its memory between your whole game (its own textures, fonts, sounds and code) and everything else open on the phone, and mobile browsers, iPhone Safari above all, reload a tab that takes too much. 32 MB of animation leaves a typical game room on a mid-range phone.
You know your game and your players' phones better than we do. To set your own line, run the game on the weakest phone you support with everything loaded that can be on screen at once, play a long session, and watch for reloads, stutters and a hot phone. A game with little other art can go higher; one with heavy art of its own may want less.
Freeing
coin.destroy(); // removes this copyDestroying a copy keeps the loaded set for the other copies. When no copy will be shown again, free it:
gs.release('./sprites/object-1/');