ecj2 / momo

[NOT MAINTAINED / ABANDONED] A simple 2D game-making library written in JavaScript.
MIT License
1 stars 0 forks source link

Be able to respond to errors #12

Closed ecj2 closed 6 years ago

ecj2 commented 6 years ago

Due to the asynchronous nature of JavaScript, it is impossible to sequentially and immediately check for errors when loading resources. Even so, it would be useful to add an asynchronous method to at least be able to acknowledge errors later on, even if nothing can be done to fix them.

Types of errors to look for:

  1. Check if a font fails to load
  2. Check if a bitmap fails to load
  3. Check if a sample fails to load*

* Samples can already be checked to see if the browser supports a given format, but nothing beyond that.

ecj2 commented 6 years ago

Adding success and failure callbacks to loading methods would be a good idea. It might also be worthwhile to add a method to shutdown Momo (to remove all timeout procedures) in the event of errors.

ecj2 commented 6 years ago

Better yet, use a promise to return resources when successful, or false if met with failure. Then use await in an async function to synchronously load resources and check for errors.

Example:

let bitmap = undefined;

async function loadResources() {

  bitmap = await Momo.loadBitmap("example.png");

  if (!bitmap) {

    // Do error handling here...
  }
}