BlueGit

timfa frameworkv3

Files

frameworkv3 / image.js

image.js

Initial Commit
timfa Tim Falken · pushed by timfa · 10 years ago
d075adff History
image.js 1.3 KiB Download Raw
1//<DOC> category Image. Create using: new image(urlToImage)
2
3function image(url)
4{
5 //<DOC> <parameter> image.subImages<br><br>The total number of subimages in the image. Defaults to 1.
6 this.subImages = 1;
7 //<DOC> <parameter> image.subImagesPerRow<br><br>The total number of subimages per row. Defaults to 1.
8 this.subImagesPerRow = 1;
9
10 $("body").append('<img id="image" src="' + url + '" style="display:none;"></img>');
11 this.g_image = $("#image")[0];
12 $("#image").attr("id","");
13
14 //<DOC> <function> image.draw(subImg, x, y, w, h, rotation)<br><br>Draw an image at (x,y), size (w,h), at an angle in degrees.
15 this.draw = function(subImg, x, y, w, h, rotation)
16 {
17 subImg %= this.subImages;
18 var context = GameWindow.canvasContext;
19 context.save();
20
21 context.translate(x, y);
22 context.rotate(rotation * (Math.PI/180));
23
24 var c = subImg % this.subImagesPerRow;
25 var r = Math.ceil(subImg / this.subImagesPerRow);
26 var sw = (this.g_image.width / this.subImagesPerRow);
27 var sh = (this.g_image.height / Math.ceil(this.subImages / this.subImagesPerRow));
28 var sx = sw * c;
29 var sy = sh * r;
30
31 context.drawImage(this.g_image, sx, sy, sw, sh, -w/2, -h/2, w, h);
32
33 context.restore();
34 }
35}