Skip to content

Graphics 2D Management

Understanding the allocation system

When you create graphics, you need to allocate them. This means that you need to create a new graphics object, and then you need to draw on it.

When you're done drawing, you need to dispose of it. This must be done by yourself in order to avoid memory leaks.

Creating a graphics

You can easily create & store 2D graphics with the following expression:

set {_graphics} to new graphics from image {_image}

Danger

As explained above, you need to dispose of the graphics when you're done drawing on it. You can do so with the following effect:

dispose {_graphics}

You won't be able to draw on the graphics after disposing it.

Drawing on a graphics

Shapes

You can draw several shapes on a graphics. You first need to create and configure the shape itself, then draw it at the specified location.

When you have a shape, you can draw it using the following effect:

draw shape {_shape} on {_graphics} at 0, 0
draw filled shape {_shape} on {_graphics} at 0, 0

Info

The colors are Skript color. You can however use color from rgb to create a color from RGB values.

For these example, we'll have a blank (transparent) image of 100x100 pixels. Also, anti-aliasing is enabled and the stroke is set to a width of 5.

set {_shape} to new rectangle with width 80 and height 80 and color yellow

rectangle.png

new rounded rectangle with width 80 and height 80 and arc width 10 and arc height 10 and color yellow

rounded-rectangle.png

set {_shape} to new arc with width 100 and height 100 and start angle 0 and arc angle 90 and color yellow

arc.png

set {_shape} to new line going to 90, 90 and color yellow

line.png

set {_shape} to new polygon with x points (50, 20, 80, 50, 20, 50) and y points (20, 80, 80, 100, 80, 80) and color yellow

polygon.png

Images

You can also draw images on the graphics:

draw {_image} on {_graphics} at 0, 0

Note

For drawing with semi-transparent colors, you need: