GithubHelp home page GithubHelp logo

seed-phaserjs-browserify's Introduction

#Phaser starting project boilerplate

This boilerplate allows you to create a phaser game were is possible to load scripts on demand.

In the example of the project you can see that the settings is in a separated .js. This file is loaded when you click on the phaser logo (simulating a settings button).

Install the boilerplate

First of all clone the project on your machine.

$ git clone https://github.com/xaviserrag/seed-phaserjs-browserify.git

Once you have the project cloned, just run npm install on the project folder.

$ cd seed-phaserjs-browserify
$ npm install browserify -g
$ npm install 

Now you have the project prepared! It's time to test it :)

$ grunt build
$ grunt server

Go to localhost:8282 and press the logo! If you open the developer tools on the networking tab, you'll see how the settings.js is downloaded when you click the logo. This is really powerful using the Phaser.Loader because you can load images just after loading the script, having the code really modularized and reducing a lot the downloading time of the game loading on demand things that are not used on the start of the game.

##How to load Modules on demand First of all, you need to create a module like settings.js, just extend some Phaser component, like a sprite, or group. Then load the images that the elements needs on that script with Phaser.Loader (you can see how i do it on the example).

The next step is to prepare the mapping.json to separate the files correctly.

Example:

   {
     "ab.js": ["./a.js, ./b.js"],
     "settings.js": ["./settings.js"]
   }

The first statement ab.js or settings.js are the output files and the others are the input files. Every file on the output will be prepared to be downloaded on demand. The first one will be the one loaded on the <script> tag.

    <script src="js/ab.js"></script>

Then if you want to load the settings.js. (In the example is loaded on the play.js). Simply use the loadjs function:

    loadjs(['./src/game/extra/settings'], function(settings) {
        self.settings = new settings(self.game);
    });

The url that you pass to the loadjs is the original url, not the build url (this is how the plugin works internally). As you can see on the example, on the callback I just create a new Settings object.

###Contributors

Tomás Casquero

seed-phaserjs-browserify's People

Contributors

xaviserrag avatar

Watchers

 avatar  avatar

Forkers

tomcask

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.