Canvallax
Canvallax copied to clipboard
Canvallax Spritesheet
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] });