Canvallax icon indicating copy to clipboard operation
Canvallax copied to clipboard

Canvallax Spritesheet

Open josephrexme opened this issue 7 years ago • 0 comments

Snippet for using spritesheets with Canvallax

(function(win){

  win._clx = win._clx || [];
  win._clx.push(function(canvallax){

    'use strict';
    
    var _originalDraw = canvallax.Image.fn.draw;    
      
    canvallax.Image.fn.draw = function(ctx,coords){
    
      if ( this.sprite && this.image ) {
        ctx.drawImage(this.image, this.sprite[0], this.sprite[1], this.width, this.height, coords[0], coords[1], this.width, this.height);
      } else { 
        _originalDraw.apply(this,arguments); 
      }
   
    };

  });

})(this);

var spriteSheet = canvallax.Image({ src: './spritesheet.png' });
var sprite = spriteSheet.clone({ sprite: [frame.x, frame.y, frame.width, frame.height] });

josephrexme avatar Jan 31 '18 21:01 josephrexme