This function will draw the given image, on the screen. Each drawImage function 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.

To draw an image it must be first loaded using the Asset Manager.

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

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

croc = new Image( 'croc.png' )

drawImage( croc, 10, 10 )
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.

croc = new Image( 'croc.png' )

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

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

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

This drawImage functions allows you to draw just one specific section of the image, to the screen. 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'.

The function is useful for building sprite sheets, where you have multiple images stored on one big image.

spries = new Image( 'sprites.png' )

// draw a 32x32 section of 'sprites' to the screen
drawImage( sprites,  0, 0, 32, 32, x, y )

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.

spries = new Image( 'sprites.png' )

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

See also

Image Class - setColor - drawRotatedImage