// Image // Constructor: new image(urlToImage, subImages = 1, subImagesPerRow = 1) function image(url, subImgTotal = 1, perRow = 1) { // image.subImages

The total number of subimages in the image. Defaults to 1. this.subImages = subImgTotal; // image.subImagesPerRow

The total number of subimages per row. Defaults to 1. this.subImagesPerRow = perRow; var body = document.body; body.insertAdjacentHTML('beforeend', ''); this.g_image = document.getElementById('image'); document.getElementById('image').id = "loadedImage"; // image.draw(sourceX, sourceY, sourceWidth, destX, destY, destWidth, destHeight, rotation, alpha)

Draw the image on screen. this.draw = function(sx, sy, sw, sh, dx, dy, dw, dh, rotation, alpha) { var shouldDraw = true; if(dx < -Math.sqrt(Math.pow(dw, 2) + Math.pow(dh, 2))) shouldDraw = false; if(dy < -Math.sqrt(Math.pow(dw, 2) + Math.pow(dh, 2))) shouldDraw = false; if(dx > GameWindow.width + Math.sqrt(Math.pow(dw, 2) + Math.pow(dh, 2))) shouldDraw = false; if(dy > GameWindow.height + Math.sqrt(Math.pow(dw, 2) + Math.pow(dh, 2))) shouldDraw = false; if(shouldDraw) { var context = GameWindow.canvasContext; context.save(); var oldAlpha = context.globalAlpha; context.globalAlpha = alpha; context.translate(dx, dy); context.rotate(rotation * (Math.PI/180)); context.drawImage(this.g_image, sx, sy, sw, sh, -dw/2, -dh/2, dw, dh); context.restore(); context.globalAlpha = oldAlpha; } } }