Giter Site home page Giter Site logo

cloudxtreme / game-asset-loader Goto Github PK

View Code? Open in Web Editor NEW

This project forked from borismus/game-asset-loader

0.0 2.0 0.0 21.73 MB

HTML5 Filesystem, offline capable loader for web game assets.

Home Page: http://smus.com/game-asset-loader

License: Apache License 2.0

JavaScript 94.55% HTML 5.45%

game-asset-loader's Introduction

Manifest format

  • assetRoot: contains the root URL under which all of the assets reside
  • bundles: an array of objects which describe groups of assets, containing:
    • name: a unique name for the group of assets
    • contents: an array containing relative pathes to each asset in the bundle
  • autoDownload: a flag that, if true, will start downloading all of the bundled assets in order as soon as GAL inits

Here is an example manifest file:

{
   "assetRoot": "url/to/assets",
   "bundles": [
     {
       "name": "unique bundle name",
       "contents": [
         "relative/path/to/asset.jpg",
         "another/asset.mp3"
       ]
     },
     ...
   ],
   "autoDownload": true
}

Sample Usage

Initializing the loader.

var gal = new GameAssetLoader("http://path.to/gal.manifest");

// Load the GAL. If manifest indicates autoDownload, this call will
// start loading assets one by one.
gal.init(function() {
   // Called when the library is initialized
});

Setup callbacks to check bundle loading completion and downloaded states.

// Set a callback so that whenever bundleName is ready to use,
gal.onLoaded("bundleName", function(info) {
   // This function is called
   // Note: if the bundle is loaded already, callback fires right away
   // info.bundleName contains the bundle that was just loaded
});

// Set a callback whenever a bundle is being loaded
gal.onProgress("bundleName", function(progress) {
   // Calls back with progress.current and progress.total whenever more
   // of the bundle is downloaded.
});

// Set a callback whenever any bundle loading causes an error
gal.onError(function(error) {
   // Error contains some stuff
});

Explicitly download a bundle (this only makes sense if autoDownload is false)

// Tell blockName to download
gal.download("blockName");

Check that a bundle is already loaded. For example, if you"re about to launch Level 5, you should ensure that Level 5 assets are loaded.

// Synchronous version of onBundleLoaded
gal.checkLoaded("bundleName", function(result) {
   // result.loaded iff successfully loaded
});

Get local URLs to downloaded assets.

var url = gal.get("image/baz.png");

game-asset-loader's People

Contributors

jhermsmeier avatar oampo avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.