take – How exactly does Lua's canvas.compose() work?

Question:

canvas:compose(x, y, canvas_src)

Make pixel-by-pixel composition between two canvases.

The canvas passed as src` is drawn over the canvas in use (canvas) in the past position.

Receive:

  • x: [number] x position of the composition.
  • y: [number] y position of the composition.
  • canvas_src: [canvas] Canvas to be rendered on top of canvas.

After the operation, the target canvas canvas has the result of the composition and the canvas src does not undergo any changes.

Source: http://www.telemidia.puc-rio.br/~francisco/nclua/referencia/canvas.html#function_compose

Example:

canvas -> 1920 x 1080
imagem -> 1280 x 720

canvas.compose(0, 0, imagem)

How should the image be rendered on canvas?

  1. The image is at the 0.0 position (left/up) with the original size of 1280×720 and there is space left at the bottom and on the right side.

  2. The image starts at position 0,0 (left/top) and is enlarged to fill the entire canvas size (1920×1080).

Answer:

  1. The image is at the 0.0 position (left/up) with the original size of 1280×720 and there is space left at the bottom and on the right side.

  2. Canvas does not auto-resize by default. To resize a canvas you can try using the function: canvas:attrSize(height, width).

Scroll to Top