This method will draw the given image, on to this Image. Each 'drawImage' method can take an optional 'isCentred' parameter, which states what the x and y location refer to. If it is false, then the image is drawn from the top-left corner. Otherwise if it is true, then it draws from the centre outwards.

.drawImage( image, x, y, isCentred=false )

Draws the given image, at the location given, onto this Image. 'isCentred' allows you to centre it around the x/y location, or not if it is omitted or false.

back = new Image( 200, 150 )
croc = new Image( 'croc.png' )

back.drawImage( croc, 10, 10 )
back.drawImage( croc, 100, 100, true )

.drawImage( image, x, y, width, height, isCentred=false )

This version of 'drawImage' allows you to scale the image when it is drawn. The width/height variables state what the size will be, in pixels.

back = new Image( 200, 150 )
croc = new Image( 'croc.png' )

// draw at double the size
back.drawImage( croc, 10, 10, croc.getWidth()*2, croc.getHeight()*2 )

// draw at a massive size!
back.drawImage( croc, 100, 10, 200, 200, false )

.drawImage( image, srcX, srcY, srcWidth, srcHeight, x, y, isCentred=false )

This 'drawImage' method allows you to draw just one specific section of the image, to this image. The result is not scaled.

'srcX' and 'srcY' refer to the top left corner of the section to drawn, from the given image. 'srcWidth' and 'srcHeight' is the size of the area to draw. 'isCentred' has no effect on the 'srcX' and 'srcY' values.

'x' and 'y' are the location where it is drawn on the screen, and like the other versions of drawImage, they are affected by the value of 'isCentred'.

.drawImage( image, srcX, srcY, srcWidth, srcHeight, x, y, width, height, isCentred=false )

The full version of drawImage, it allows you to draw a sub-section of an image, and have it scaled when it is drawn.

back = new Image( 200, 150 )
spries = new Image( 'sprites.png' )

// Draw a 32x32 section of 'sprites' to the screen,
// but at double the size.
back.drawImage( sprites,  0, 0, 32, 32, x, y, 64, 64 )

See also

setColor - drawRotatedImage