Meteor 2 Scripting Functions
Drawing
void setDrawLayer(int layer)
Set the current drawing layer.

Example
void onUpdate(float deltaTime)
{
    // draw transparent red box to LAYER_LIGHT_EFFECTS layer
    setDrawLayer(LAYER_LIGHT_EFFECTS);
    drawRectangleWH(10, 10, 100, 100, colToHtml(255,0,0,128), true);
    setDefaultDrawLayer();
}

Comments
Use setDefaultDrawLayer() to revert back to default layer.
Valid layers are:
LAYER_CURRENT
LAYER_DISPLAY
LAYER_WORLD
LAYER_UI (default)
LAYER_UI_LIGHTING
LAYER_LIGHTING
LAYER_LIGHT_EFFECTS
LAYER_NIGHT_VISION
LAYER_THERMAL_IMAGING

See also
setDefaultDrawLayer getDrawLayer

void setDefaultDrawLayer()
Set the current drawing layer back to default.

See also
setDrawLayer getDrawLayer

int getDrawLayer()
Get the current drawing layer.

See also
setDrawLayer setDefaultDrawLayer

void drawText(vector2 pos, string text, string colour, bool outline, int fontNumber, int fontSize)
Draws UI text to the screen for the current frame.

Example
void onUpdate(float deltaTime)
{
    if(gameHasFocus())
    {
        // draw red white size 20 text at screen position 100, 100
        drawText(vector2(100,100), "Hello World!", "#FFFFFF", true, FONT_STANDARD, 20);
    }
}

Comments
Call from onUpdate event to draw every frame.
colour is specfified in HTML style ("#RRGGBB" hex values), colours may also contain 2 additional optional characters for alpha (e.g. "#FFFFFF80" is transparent white).
Use outline to make the text easier to read.
Valid fonts are: FONT_STANDARD (Default font), FONT_UAV (UAV style font) or FONT_MONO (Mono/fixed character width font).

See also
getFontHeight getTextWidth

int getDefaultFontSize(int fontNumber)
Get the default/native point size a font.

Example
print("Default font sizes");
print("Standard: " + getDefaultFontSize(FONT_STANDARD));
print("Mono: " + getDefaultFontSize(FONT_MONO));
print("UAV: " + getDefaultFontSize(FONT_UAV));

See also
drawText getTextWidth

void getFontHeight(int fontNumber, int fontSize)
Get the height of a font in pixels.

Example
void onUpdate(float deltaTime)
{
    if(gameHasFocus())
    {
        int font = FONT_STANDARD;
        int fontSize = getDefaultFontSize(FONT_STANDARD);

        vector2 drawPos = vector2(100, 100);

        for(int i=0; i<10; i++)
        {
            drawText(drawPos, "This is line " + (i+1), "#FFFFFF", true, font, fontSize);
        
            // move down one line
            drawPos.y += getFontHeight(font, fontSize);
        }
    }
}

See also
drawText getDefaultFontSize getTextWidth

void getTextWidth(string text, int fontNumber, int fontSize)
Get the width of a string of text in pixels.

Example
void onUpdate(float deltaTime)
{
    if(gameHasFocus())
    {
        int font = FONT_UAV;
        int fontSize = getDefaultFontSize(FONT_UAV);

        string text = "I am in the middle of the screen";

        vector2 drawPos = vector2(
            (SCREEN_W - getTextWidth(text, font, fontSize)) * 0.5,
            (SCREEN_H - getFontHeight(font, fontSize)) * 0.5 );

        drawText(drawPos, text, "#FFFFFF", true, font, fontSize);
    }
}

See also
drawText getDefaultFontSize getFontHeight

void drawRectangle(float x1, float y1, float x2, float y2, string colour, bool fill, float outlineThickness=2)
Draw a rectangle using absolute coordinates.

Example
void onUpdate(float deltaTime)
{
    if(gameHasFocus())
    {
        // draw 100 by 100 transparent black rectangle near upper left corner
        drawRectangle(10, 10, 110, 110, "#00000080", true);
    }
}

Comments
colour is specfified in HTML style ("#RRGGBB" hex values), colours may also contain 2 additional optional characters for alpha (e.g. "#FFFFFF80" is transparent white).

See also
drawRectangleWH drawRectangleWHCentred

void drawRectangleWH(vector2 topLeftPos, vector2 totalSize, string colour, bool fill, float outlineThickness=2)
Draw a rectangle at the specified top-left position and width/height.

Example
void onUpdate(float deltaTime)
{
    if(gameHasFocus())
    {
        // draw 200 by 100 transparent black rectangle near upper left corner
        drawRectangleWH(vector2(10, 10), vector2(200, 100), "#00000080", true);
    }
}

Comments
colour is specfified in HTML style ("#RRGGBB" hex values), colours may also contain 2 additional optional characters for alpha (e.g. "#FFFFFF80" is transparent white).

See also
drawRectangle drawRectangleWHCentred

void drawRectangleWHCentred(vector2 centrePos, vector2 totalSize, string colour, bool fill, float outlineThickness=2)
Draw a rectangle at the specified centre position and size.

Example
void onUpdate(float deltaTime)
{
    if(gameHasFocus())
    {
        // draw 100 by 100 transparent black rectangle near upper left corner
        drawRectangleWHCentred(vector2(60, 60), vector2(100, 100), "#00000080", true);
    }
}

Comments
colour is specfified in HTML style ("#RRGGBB" hex values), colours may also contain 2 additional optional characters for alpha (e.g. "#FFFFFF80" is transparent white).

See also
drawRectangle drawRectangleWH drawRectangleRotated

void drawRectangleRotated(vector2 centrePos, vector2 totalSize, float angle, string colour, bool fill, float outlineThickness=2)
Draw a rectangle at the specified centre position and size with rotation.

Example
void onUpdate(float deltaTime)
{
    if(gameHasFocus())
    {
        // draw 100 by 100 transparent black rectangle rotated at 45 degrees near upper left corner
        drawRectangleRotated(vector2(60, 60), vector2(100, 100), , 45, "#00000080", true);
    }
}

See also
drawRectangleWHCentred

void drawTriangle(vector2 point1, vector2 point2, vector2 point3, string colour, float thickness=2)
Draw a triangle at the specified positions.

Example
void onUpdate(float deltaTime)
{
    if(gameHasFocus())
    {
        // draw a green outline triangle
        drawTriangle(vector2(100, 0), vector2(200, 200), vector2(0, 200), "#00FF00", false);
    }
}

Comments
colour is specfified in HTML style ("#RRGGBB" hex values), colours may also contain 2 additional optional characters for alpha (e.g. "#FFFFFF80" is transparent white).

void drawCircleCentred(vector2 centrePos, float radius, string colour, bool fill, float thickness=2)
Draw a circle at the specified centre position.

Example
void onUpdate(float deltaTime)
{
    if(gameHasFocus())
    {
        drawCircleCentred(vector2(100, 0), vector2(200, 200), vector2(0, 200), "#00FF00", false);
    }
}

Comments
colour is specfified in HTML style ("#RRGGBB" hex values), colours may also contain 2 additional optional characters for alpha (e.g. "#FFFFFF80" is transparent white).

void drawLine(vector2 point1, vector2 point2, string colour, float thickness=2)
Draw a rectangle at the specified centre position and size.

Example
void onUpdate(float deltaTime)
{
    if(gameHasFocus())
    {
        // draw a red line from top-left to bottom right corner.
        drawLine(vector2(0, 0), vector2(SCREEN_W - 1, SCREEN_H -1), "#FF0000");
    }
}

Comments
colour is specfified in HTML style ("#RRGGBB" hex values), colours may also contain 2 additional optional characters for alpha (e.g. "#FFFFFF80" is transparent white).

int getSpriteNumber(string spriteFilename)
Resolve a sprite filename to a sprite number.

Example
print(getSpriteNumber("objects\\arrow.spr"));

Comments
Returns -1 if the sprite file was not found.
Sprite numbers are local only.

See also
getSpriteFramesCount getSpriteFrameSize drawSprite drawSpriteFrame

int getSpriteFramesCount(int spriteNumber)
Get the number of frames in a sprite.

Example
int spriteNumber = getSpriteNumber("ASCOUT.SPR");
print(getSpriteFramesCount(spriteNumber));

Comments
Returns 0 if the sprite file was not found.

See also
getSpriteNumber getSpriteFrameSize drawSprite drawSpriteFrame

vector2 getSpriteFrameSize(int spriteNumber, int frameNumber)
Get the size of a sprite frame in pixels.

Example
int spriteNumber = getSpriteNumber("ASCOUT.SPR");
print(getSpriteFrameSize(spriteNumber, 0));

Comments
Returns 0,0 if the sprite file or frame was not found.

See also
getSpriteNumber getSpriteFramesCount drawSprite drawSpriteFrame

void drawSprite(vector2 pos, int spriteNumber, float angle=0, vector2 scale=vector2(1,1))
Draw a sprite to the screen UI.

Example
int spriteArrow = 0;
float arrowSpriteAngle = 0;

void onWorldStart()
{
    // it is faster not to resolve this every frame
    spriteArrow = getSpriteNumber("objects\\arrow.spr");
}

void onUpdate(float deltaTime)
{
    if(gameHasFocus())
    {
        if(spriteArrow != -1)
        {
            arrowSpriteAngle += (deltaTime * 100);

            // draw sprite in middle of screen
            drawSprite(getScreenSize() * 0.5, spriteArrow);

            // draw rotated sprite to upper left of screen
            drawSprite(getScreenSize() * 0.3, spriteArrow, arrowSpriteAngle);

            // draw rotated scaled sprite to lower right of screen
            drawSprite(getScreenSize() * 0.7, spriteArrow, 360 - arrowSpriteAngle, vector2(3,3));
        }
    }
}

Comments
The sprite will animate automatically.

See also
getSpriteNumber getSpriteFramesCount getSpriteFrameSize drawSpriteFrame drawImage

void drawSpriteFrame(vector2 pos, int spriteNumber, int frameNumber, float angle=0, vector2 scale=vector2(1,1), string colour="#FFFFFF")
Draw a sprite frame to the screen UI.

Example
int spriteArrow = -1;

void onWorldStart()
{
    // it is faster not to resolve this every frame
    spriteArrow = getSpriteNumber("objects\\arrow.spr");
}

void onUpdate(float deltaTime)
{
    if(gameHasFocus())
    {
        if(spriteArrow != -1)
        {
            if(mouseButtonDown(2))
            {
                // draw frame 0 rotated and using transparency if right mouse button is held
                drawSpriteFrame(mousePos(), spriteArrow, 0, 180, vector2(1, 1), "#FFFFFF80");
            }
            else
            {
                // draw frame 0 normally
                drawSpriteFrame(mousePos(), spriteArrow, 0);
            }
        }
    }
}

Comments
Use to draw a single sprite frame without animation.
angle, scale and colour are optional.

See also
getSpriteNumber getSpriteFramesCount getSpriteFrameSize drawSprite drawImage

int getImageNumber(string imageFilename)
Resolve a image filename to a sprite number.

Example
print(getImageNumber("objects\\arrow01_01.png"));

Comments
Image filenames are specified inside ini files in the graphics\ folder (e.g. for imageName=objects\arrow01_01.png use objects\\arrow01_01.png)
Returns -1 if the image file was not found.
Image numbers are local only.

See also
drawImage

vector2 getImageSize(int imageNumber)
Get the size of an image in pixels.

Example
int imageNumber = getImageNumber("objects\\arrow01_01.png");
print(getImageSize(imageNumber, 0));

Comments
Returns 0,0 if the image file was not found.

See also
getImageNumber drawImage

void drawImage(vector2 pos, int imageNumber, float angle=0, vector2 scale=vector2(1,1), string colour="#FFFFFF")
Draw an image from the graphics\ folder to the screen UI.

Example
int imageArrow = -1;

void onWorldStart()
{
    // it is faster not to resolve this every frame
    imageArrow = getImageNumber("objects\\arrow01_01.png");
}

void onUpdate(float deltaTime)
{
    if(gameHasFocus())
    {
        if(imageArrow != -1)
        {
            if(mouseButtonDown(2))
            {
                // draw image rotated and using transparency if right mouse button is held
                drawImage(mousePos(), imageArrow, 180, vector2(1, 1), "#FFFFFF80");
            }
            else
            {
                // draw image normally
                drawImage(mousePos(), imageArrow);
            }
        }
    }
}

Comments
Use to draw a image directly name or draw an image that does not have a sprite.
angle, scale and colour are optional.

See also
getImageNumber getImageSize drawSprite drawSpriteFrame

void drawCrtEffectOverlay()
Draw CRT effect overlay.

Example
void onUpdate(float deltaTime)
{
    drawCrtEffectOverlay();
}

Comments
Use to draw a CRT effect overlay with lines between pixels.

See also
drawScopeEffectOverlay drawMonitorEffectOverlay

void drawScopeEffectOverlay()
Draw scope effect overlay.

Example
void onUpdate(float deltaTime)
{
    drawScopeOverlay(vector2(SCREEN_W * 0.5f, SCREEN_H * 0.5f), SCREEN_H * 0.5f);
}

Comments
Use to draw a black background with a hole to simulate looking down a scope.

See also
drawCrtEffectOverlay drawMonitorEffectOverlay

void drawMonitorEffectOverlay()
Draw monitor effect overlay.

Example
void onUpdate(float deltaTime)
{
    drawMonitorEffectOverlay(getMousePos(), vector2(SCREEN_W * 0.5f, SCREEN_H * 0.5f));
}

Comments
Use to draw a black background with a rectangular hole to simulate looking at a monitor/screen.

See also
drawCrtEffectOverlay drawScopeOverlay


Index