jjCANVAS class JJ2+
Drawing surface passed to the HUD and layer drawing hooks
The HUD hooks (onDraw*) receive a canvas covering one player's view, the onDrawLayer# hooks one that draws into the level at the depth of that layer. A canvas is only valid while the hook runs. Its methods draw pixels, rectangles, tiles, sprites and text immediately; whatever is drawn later in the frame covers what was drawn before. Most methods take a SPRITE::Mode and its parameter, which control how the colors are rendered. Nothing drawn this way interacts with the level.
Functions
- void drawPixel(int xPixel, int yPixel, uint8 color, SPRITE::Mode mode = SPRITE::NORMAL, uint8 param = 0)
- Draws a single pixel
- void drawRectangle(int xPixel, int yPixel, int width, int height, uint8 color, SPRITE::Mode mode = SPRITE::NORMAL, uint8 param = 0)
- Draws a filled rectangle
- void drawResizedSprite(int xPixel, int yPixel, int setID, uint8 animation, uint8 frame, float xScale, float yScale, SPRITE::Mode mode = SPRITE::NORMAL, uint8 param = 0)
- Draws a scaled frame of an animation set
- void drawResizedSpriteFromCurFrame(int xPixel, int yPixel, uint sprite, float xScale, float yScale, SPRITE::Mode mode = SPRITE::NORMAL, uint8 param = 0)
- Draws a scaled frame given by its index in jjAnimFrames
- void drawRotatedSprite(int xPixel, int yPixel, int setID, uint8 animation, uint8 frame, int angle, float xScale = 1, float yScale = 1, SPRITE::Mode mode = SPRITE::NORMAL, uint8 param = 0)
- Draws a rotated and scaled frame of an animation set
- void drawRotatedSpriteFromCurFrame(int xPixel, int yPixel, uint sprite, int angle, float xScale = 1, float yScale = 1, SPRITE::Mode mode = SPRITE::NORMAL, uint8 param = 0)
- Draws a rotated and scaled frame given by its index in jjAnimFrames
- void drawSprite(int xPixel, int yPixel, int setID, uint8 animation, uint8 frame, int8 direction = 0, SPRITE::Mode mode = SPRITE::NORMAL, uint8 param = 0)
- Draws a frame of an animation set
- void drawSpriteFromCurFrame(int xPixel, int yPixel, uint sprite, int8 direction = 0, SPRITE::Mode mode = SPRITE::NORMAL, uint8 param = 0)
- Draws a frame given by its index in jjAnimFrames
- void drawString(int xPixel, int yPixel, const string&in text, const jjANIMATION&in animation, STRING::Mode mode = STRING::NORMAL, uint8 param = 0) partially supported
- Draws text using the frames of an animation as the font
- void drawString(int xPixel, int yPixel, const string&in text, const jjANIMATION&in animation, const jjTEXTAPPEARANCE&in appearance, uint8 param1 = 0, SPRITE::Mode spriteMode = SPRITE::PALSHIFT, uint8 param2 = 0) partially supported
- Draws text using the frames of an animation as the font, with a custom appearance
- void drawString(int xPixel, int yPixel, const string&in text, STRING::Size size = STRING::SMALL, STRING::Mode mode = STRING::NORMAL, uint8 param = 0) partially supported
- Draws text in one of the built-in font sizes
- void drawString(int xPixel, int yPixel, const string&in text, STRING::Size size, const jjTEXTAPPEARANCE&in appearance, uint8 param1 = 0, SPRITE::Mode spriteMode = SPRITE::PALSHIFT, uint8 param2 = 0) partially supported
- Draws text in one of the built-in font sizes with a custom appearance
- void drawSwingingVineSpriteFromCurFrame(int xPixel, int yPixel, uint sprite, int length, int curvature, SPRITE::Mode mode = SPRITE::NORMAL, uint8 param = 0)
- Draws a frame bent like a swinging vine
- void drawTile(int xPixel, int yPixel, uint16 tile, TILE::Quadrant tileQuadrant = TILE::ALLQUADRANTS)
- Draws a tile of the tile set
Function documentation
void jjCANVAS:: drawPixel(int xPixel,
int yPixel,
uint8 color,
SPRITE::Mode mode = SPRITE::NORMAL,
uint8 param = 0)
Draws a single pixel
The pixel at the given position gets the palette color with index color, rendered in the sprite mode. For many pixels, a sprite of your own is usually the better choice.
void jjCANVAS:: drawRectangle(int xPixel,
int yPixel,
int width,
int height,
uint8 color,
SPRITE::Mode mode = SPRITE::NORMAL,
uint8 param = 0)
Draws a filled rectangle
The top left corner is at the given position, the rectangle is width by height pixels in the palette color with index color. In most BLEND_ sprite modes, param acts as the opacity (255 is opaque).
void jjCANVAS:: drawResizedSprite(int xPixel,
int yPixel,
int setID,
uint8 animation,
uint8 frame,
float xScale,
float yScale,
SPRITE::Mode mode = SPRITE::NORMAL,
uint8 param = 0)
Draws a scaled frame of an animation set
Like drawSprite(), but the frame is stretched by xScale and yScale instead of taking a direction. A negative scale flips the sprite on that axis. No smoothing is applied.
void jjCANVAS:: drawResizedSpriteFromCurFrame(int xPixel,
int yPixel,
uint sprite,
float xScale,
float yScale,
SPRITE::Mode mode = SPRITE::NORMAL,
uint8 param = 0)
Draws a scaled frame given by its index in jjAnimFrames
Same as drawResizedSprite(), but the frame is a single index.
void jjCANVAS:: drawRotatedSprite(int xPixel,
int yPixel,
int setID,
uint8 animation,
uint8 frame,
int angle,
float xScale = 1,
float yScale = 1,
SPRITE::Mode mode = SPRITE::NORMAL,
uint8 param = 0)
Draws a rotated and scaled frame of an animation set
angle uses 1024 units per full turn (as jjSin() does) and turns the sprite counter-clockwise about its hotspot; 0 leaves it unrotated. The sprite is scaled by xScale and yScale before it is rotated.
void jjCANVAS:: drawRotatedSpriteFromCurFrame(int xPixel,
int yPixel,
uint sprite,
int angle,
float xScale = 1,
float yScale = 1,
SPRITE::Mode mode = SPRITE::NORMAL,
uint8 param = 0)
Draws a rotated and scaled frame given by its index in jjAnimFrames
Same as drawRotatedSprite(), but the frame is a single index.
void jjCANVAS:: drawSprite(int xPixel,
int yPixel,
int setID,
uint8 animation,
uint8 frame,
int8 direction = 0,
SPRITE::Mode mode = SPRITE::NORMAL,
uint8 param = 0)
Draws a frame of an animation set
setID is an ANIM::Set value, animation the index of the animation in that set and frame the index of the frame in the animation, all counted from 0. The frame's hotspot lands on the given position.
direction flips the sprite: negative values flip it horizontally, values from 64 to 127 vertically and values from -128 to -65 both ways. The SPRITE::Direction constants name these cases.
void jjCANVAS:: drawSpriteFromCurFrame(int xPixel,
int yPixel,
uint sprite,
int8 direction = 0,
SPRITE::Mode mode = SPRITE::NORMAL,
uint8 param = 0)
Draws a frame given by its index in jjAnimFrames
Same as drawSprite(), but the frame is a single index, such as the curFrame of an object or a player.
void jjCANVAS:: drawString(int xPixel,
int yPixel,
const string&in text,
const jjANIMATION&in animation,
STRING::Mode mode = STRING::NORMAL,
uint8 param = 0)
Draws text using the frames of an animation as the font
Frame 0 of the animation is the space and each further frame the next character code, as in the built-in font animations. A space is 7 pixels wide, other characters as wide as their frames. @ and line feeds start a new line, and |, #, ~, ^ and § are left out. mode is a STRING::Mode: RIGHTALIGN ends the text at the given position and PALSHIFT shifts the colors by param palette entries.
void jjCANVAS:: drawString(int xPixel,
int yPixel,
const string&in text,
const jjANIMATION&in animation,
const jjTEXTAPPEARANCE&in appearance,
uint8 param1 = 0,
SPRITE::Mode spriteMode = SPRITE::PALSHIFT,
uint8 param2 = 0)
Draws text using the frames of an animation as the font, with a custom appearance
Uses spacing and align of the appearance, and draws the special characters it sets to STRING::DISPLAYSIGN as regular characters. The text is drawn in spriteMode with param2.
void jjCANVAS:: drawString(int xPixel,
int yPixel,
const string&in text,
STRING::Size size = STRING::SMALL,
STRING::Mode mode = STRING::NORMAL,
uint8 param = 0)
Draws text in one of the built-in font sizes
size is a STRING::Size and mode a STRING::Mode: DARK draws dimmed text, RIGHTALIGN ends the text at the given position, BOUNCE and SPIN move the letters, and PALSHIFT shifts the font colors by param palette entries. The x coordinate can also select alignment, see jjTEXTAPPEARANCE::align. Characters whose frames a script replaced in the font animations are drawn with those frames.
void jjCANVAS:: drawString(int xPixel,
int yPixel,
const string&in text,
STRING::Size size,
const jjTEXTAPPEARANCE&in appearance,
uint8 param1 = 0,
SPRITE::Mode spriteMode = SPRITE::PALSHIFT,
uint8 param2 = 0)
Draws text in one of the built-in font sizes with a custom appearance
Uses spacing, align and newline of the appearance, and lets the letters bounce or spin when its amplitudes are non-zero.
void jjCANVAS:: drawSwingingVineSpriteFromCurFrame(int xPixel,
int yPixel,
uint sprite,
int length,
int curvature,
SPRITE::Mode mode = SPRITE::NORMAL,
uint8 param = 0)
Draws a frame bent like a swinging vine
The frame is drawn length rows down from the given position, repeating from its top if it is shorter. Each row is shifted sideways by curvature * row * row / 4194304 pixels, and the vine gets one row shorter for every 2048 of the curvature. Pixels with palette index 128 are treated as transparent, as vine graphics expect.
void jjCANVAS:: drawTile(int xPixel,
int yPixel,
uint16 tile,
TILE::Quadrant tileQuadrant = TILE::ALLQUADRANTS)
Draws a tile of the tile set
The tile's top left corner is at the given position. tile may include the TILE::HFLIPPED, TILE::VFLIPPED and TILE::ANIMATED flags. With a tileQuadrant other than TILE::ALLQUADRANTS, only that quarter of the tile is drawn, at its place within the tile. This only draws; it doesn't add anything solid to the level.