Skip to content

Instantly share code, notes, and snippets.

@mmurray
Created November 17, 2010 00:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mmurray/702799 to your computer and use it in GitHub Desktop.
Save mmurray/702799 to your computer and use it in GitHub Desktop.
function CroppedImage(image,sx,sy,sw,sh){
this.image = image;
this.sx = sx;
this.sy = sy;
this.sw = sw;
this.sh = sh;
}
CroppedImage.prototype.draw = function(context,x,y){
context.drawImage(this.image, this.sx, this.sy, this.sw, this.sh, x, y, this.sw, this.sh)
}
//Usage:
var sprite1 = new CroppedImage(img1, 0, 0, 25, 25);
var sprite2 = new CroppedImage(img1, 0, 25, 25, 25);
sprite1.draw(context, 0, 0);
sprite2.draw(context, 34, 62);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment