Created
November 17, 2010 00:35
-
-
Save mmurray/702799 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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