melonJS boilerplate
jsFiddle template for melonJS
by obiot
HTML
<script src="https://github.com/melonjs/melonJS/releases/download/4.0.0/melonJS.js"></script>
<!-- Canvas placeholder -->
<div id="screen"></div>
JavaScript
<!-- init the melonJS Library -->
me.boot();
<!-- game template -->
var game = {
// assets to preload
assets: [{
name: "logo",
type: "image",
src: "http://melonjs.org/media/icons/HTML5_Badge.png"
}],
// Run on page load.
"onload": function() {
// Initialize the video.
if (!me.video.init(960, 640, {
wrapper: "screen",
scale: "auto"
})) {
alert("Your browser does not support HTML5 canvas.");
return;
}
// Initialize the audio.
me.audio.init("mp3,ogg");
// set and load all resources.
// (this will also automatically switch to the loading screen)
me.loader.preload(game.assets, this.loaded.bind(this));
},
// Run on game resources loaded.
"loaded": function() {
var PlayScreen = me.ScreenObject.extend({
// on reset event function
onResetEvent: function() {
// clear the screen
me.game.world.addChild(new me.ColorLayer("background", "#202020"), 0);
// hello world !
console.log("hello world");
}
});
// set the "Play/Ingame" Screen Object
me.state.set(me.state.PLAY, new PlayScreen());
// switch to PLAY state
me.state.change(me.state.PLAY);
}
};
<!-- run the game boostrap -->
game.onload();