Monwarp ResourceManager example

by monteslu

HTML

<canvas id="canvas" style="border: 1px solid black;"  width="300" height="300"></canvas>

JavaScript

require({
  packages: [
    { name: 'mwe', location: 'https://raw.github.com/monteslu/monwarp/master/src/mwe/' }
  ]

}, [
  'mwe/GameCore'
], function(GameCore){
    
    //position and velocities
    var sprite = {
        x:0, y:0, dx:0.05, dy:0.05
    };
    
    
    var game = new GameCore({
      canvasId: 'canvas',
      loadResources: function(rm){
        //will have game wait until image is loaded
        sprite.img = rm.loadImage('http://lorempixel.com/50/50/');
        this.backgroundImg = rm.loadImage('http://lorempixel.com/300/300/');
      },
      update: function(timeElapsed){
        sprite.x += sprite.dx * timeElapsed;
        sprite.y += sprite.dy * timeElapsed;
      },
      draw: function(ctx){
        ctx.drawImage(this.backgroundImg, 0, 0);
        ctx.drawImage(sprite.img, sprite.x, sprite.y);
      }    
    });

    game.run();
    
});