Loading and error screens
Before a game starts, its loading screen loads the models and sounds of the unit types it starts with, with a progress bar; the rest load behind the game. If something fails, the error screen shows what happened, Load again, the last save and the way out.
Quick start
gameScene({
id: 'play',
game,
loading: { text: 'Raising the banners…', picture: '/logo.png', background: '/splash.jpg' },
error: { title: 'The battle could not start', text: 'Try again, or load your last save.' },
onCrash: (report) => sendToMyServer(report) // the library sends nothing by itself
})A loading screen with your words and picture, an error screen with your words, and crash reports to your own server.
Common tasks
Draw your own loading screen
loading: {
component: (props) => (
<LoadingScreen>
<MyTips />
</LoadingScreen> // children go between the words and the bar
)
}
loading: { mount: (element, progress) => drawBar(element, progress()) } // progress(): { done, total, parts }The pieces: LoadingScreen, LoadingPicture, LoadingText, LoadingMeter (@v12-engine/client/app). The client's screen also turns a Spinner (@v12-engine/client/kit) from the first moment until the game is on, and the app shows one over the scene before while the next is prepared out of sight.
Load more, or less, before the game starts
files: {
preload: 'all', // every unit type before the game ('map', the default: what the game starts with and what those make)
later: ['lich'] // big types left out of the loading screen
}
client.preload({ models: ['knight', modelDef], sounds: ['hit'], textures: ['/splash.png'] }, ({ done, total, parts }) => draw(done / total))
client.loadUnits(['lich']) // before the boss's waveWhat shows up before its model is there is drawn with its parts until it is.
Wrap the client's error screen
error: { component: (props) => <MyFrame><ErrorScreen {...props} /></MyFrame> }
error: { mount: (element, report, actions) => drawError(element, report, actions) }Download or copy a crash report
crashReportText(report) // JSON text
downloadCrashReport(report) // a file with the save and the replayThe client's error screen has these under Details: what threw, the last log lines, Copy report, Download.
Reference
GameScene.loading
| Field | What |
|---|---|
text | words |
picture | a picture (LoadingPicture) |
background | behind it |
component | your own (given progress()) |
mount | (element, progress) => dispose |
A game with a loading screen shows it at once while the next scene builds.
Error screen
error and onCrash are options of launch and of a game scene; for a page that builds a game itself, onCrash is runGame's and error is GameMount's. title may be a function of the report. onError, onCrash(report) and client.onStop hear it.
What triggers it: an error thrown in a frame (outside the view's guarded hooks, see HUD › When a frame fails), a lost graphics device, the rules ending the game on an error (Rules.onError), or a game that could not load. After a lost device, a game played in the page is saved as it stood and reloaded from it when the device comes back. Errors nothing caught (error, unhandledrejection) are logged (category page) and the game goes on.
A crash report (CrashReport)
Plain data: the kind (load, frame, device, rules), the message, the error, where, the game with its version and hash, the tick, the log's last hundred entries, and for a game played in the page the world as it stood (save) and its replay so far (replay).