The Max2D module provides a set of commands for drawing 2D graphics.

Before using any of the Max2D commands, you must first create a Max2D graphics object. The easiest way to do this is using the #Graphics command.

By default, Max2D is double buffered which means you will have to use #Flip once you have finished drawing each frame of graphics.

Drawing

Max2D provides support for the following drawing commands:

Drawing commandAction
ClsClears the viewport
PlotDraws a single pixel
DrawLineDraws a line
DrawRectDraws a rectangle
DrawOvalDraws an oval
DrawPolyDraws a polygon
DrawTextDraws some text
DrawImageDraws an image
DrawPixmapDraws a pixmap

Viewport, origin and handle

Drawing commands are clipped to a rectangular area known as the viewport. Only the area within the viewport is ever modified, and attempting to draw outside the viewport will result in the drawing command being clipped or chopped to the viewport. To set the viewport, use the SetViewport command.

Drawing commands are also offset by the current origin and handle. To set these properties, use the SetOrigin and SetHandle commands.

The current handle is an x,y coordinate subtracted from all drawing x,y coordinates before any rotation or scaling occurs. This allows you to provide a local 'center' for drawing. On the other hand, the current origin is an x,y coordinate added to all drawing x,y coordinates after any rotation or scaling.

Color, alpha and blend mode

Drawing commands are affected by the current color, alpha and blend mode. You can set these properties by using the SetColor, SetAlpha and SetBlend commands.

The current alpha value controls the transparency level when using the ALPHABLEND blend mode.

The current blend mode controls how pixels are combined with existing pixels in the back buffer and can be one of the following:

Blend modeEffect
SOLIDBLENDPixels overwrite existing backbuffer pixels
MASKBLENDPixels are drawn only if their alpha component is greater than .5
ALPHABLENDPixels are alpha blended with existing backbuffer pixels
LIGHTBLENDPixel colors are added to backbuffer pixel colors, giving a 'lighting' effect
SHADEBLENDPixel colors are multiplied with backbuffer pixel colors, giving a 'shading' effect

Rotation and scale

Drawing commands can be scaled and rotated using the SetScale and SetRotation commands. Rotation and scaling occur relative to the current handle.

Images

Images are pre-rendered chunks of graphics that can be efficiently drawn using a single DrawImage command. Images are typically stored in png, bmp or jpg format, and can be loaded using the LoadImage command.

Image drawing is also affected by color, alpha, blend, rotation and scale. The current color is multiplied with each pixel color before the image is drawn to the backbuffer, allowing you to tint images. To disable this effect, you should set the current color to white.

Images can also have a mask color. This is the color that represents transparency when an image is drawn using the MASKBLEND blend mode. To set the mask color, use the SetMaskColor command.

Images can be created by snapshotting regions of the back buffer using the GrabImage command.

Pixmaps

Pixmaps are used to manipulate images at a pixel level, see the #pixmaps module for details.

LockImage allows for direct Image pixel access and requires a corresponding call to UnlockImage when you have have finished reading or modifying the pixels. The DrawPixmap and GrabPixmap commands allow you to move pixels to and from the current graphic display's backbuffer.

Collisions

Max2D features a multilayered pixel perfect collision system. The CollideRect and CollideImage commands provide a dual function allowing the drawing and hit testing of Rects and Images with any combination of 32 collision layers.

The current Scale, Rotation, Origin and Handle settings are taken into account so coordinates for the collision commands acurately match their drawing counterparts DrawRect and DrawImage.

ResetCollisions is used to clear any or all of the 32 collision layers provided.