Class Canvas
java.lang.Object
org.openpatch.scratch.extension.Canvas
What a layer drawer draws with: it records into the draw list, nothing is drawn at once and no
OpenGL is exposed. Coordinates are those of the layer: world coordinates (Scratch's, y up) for
the world layers, stage coordinates for the UI layer and the overlay. Game thread only, and only
during the drawer's call.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclip(double x, double y, double width, double height) Draws only inside a rectangle (axis-aligned on the screen) untilnoClip().voidAn image (a file or a built-in sprite name), centred on a point.voiddrawImageQuad(String path, int sx, int sy, int sw, int sh, double[] corners) A region of an image on any quad: turned, mirrored, sheared.voiddrawImageRegion(String path, int sx, int sy, int sw, int sh, double x, double y, double width, double height) A region of an image, centred on a point: one tile of a tileset, one glyph of a bitmap font.voiddrawOutline(double[] xs, double[] ys, Color stroke, double weight) The outline of a polygon.voiddrawPolygon(double[] xs, double[] ys, Color fill) A filled polygon, concave ones included.voiddrawRectangle(double x, double y, double width, double height, Color fill) A filled rectangle centred on a point.voidA line of text whose first baseline starts at a point, in the default font.intimageHeight(String path) intimageWidth(String path) voidnoClip()Draws everywhere again.voidsetOpacity(double opacity)
-
Method Details
-
setOpacity
public void setOpacity(double opacity) - Parameters:
opacity- how opaque what follows is drawn, 0 to 1
-
drawImage
An image (a file or a built-in sprite name), centred on a point.- Parameters:
path- the imagex- x of its centrey- y of its centrewidth- its widthheight- its height
-
drawImageRegion
public void drawImageRegion(String path, int sx, int sy, int sw, int sh, double x, double y, double width, double height) A region of an image, centred on a point: one tile of a tileset, one glyph of a bitmap font.- Parameters:
path- the imagesx- the region's left edge in image pixelssy- its top edgesw- its widthsh- its heightx- x of the centrey- y of the centrewidth- the width to draw it atheight- the height to draw it at
-
drawImageQuad
A region of an image on any quad: turned, mirrored, sheared.- Parameters:
path- the imagesx- the region's left edge in image pixelssy- its top edgesw- its widthsh- its heightcorners- where the region's top-left, top-right, bottom-right and bottom-left corners go:x0, y0, …, x3, y3
-
drawPolygon
A filled polygon, concave ones included.- Parameters:
xs- x of every cornerys- y of every corner, in the same orderfill- its colour
-
drawOutline
The outline of a polygon.- Parameters:
xs- x of every cornerys- y of every cornerstroke- the outline's colourweight- the outline's width
-
drawRectangle
A filled rectangle centred on a point.- Parameters:
x- x of its centrey- y of its centrewidth- its widthheight- its heightfill- its colour
-
drawText
-
clip
public void clip(double x, double y, double width, double height) Draws only inside a rectangle (axis-aligned on the screen) untilnoClip().- Parameters:
x- x of its centrey- y of its centrewidth- its widthheight- its height
-
noClip
public void noClip()Draws everywhere again. -
imageWidth
- Parameters:
path- an image or a built-in sprite name- Returns:
- its width in pixels
-
imageHeight
- Parameters:
path- an image or a built-in sprite name- Returns:
- its height in pixels
-