Meteor 2 Scripting Functions
Drawing
void setDrawLayer(int layer)
Set the current drawing layer.
void onUpdate(float deltaTime)
{
setDrawLayer(LAYER_LIGHT_EFFECTS);
drawRectangleWH(10, 10, 100, 100, colToHtml(255,0,0,128), true);
setDefaultDrawLayer();
}
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
void setDefaultDrawLayer()
Set the current drawing layer back to default.
int getDrawLayer()
Get the current drawing layer.
void drawText(vector2 pos, string text, string colour, bool outline, int fontNumber, int fontSize)
Draws UI text to the screen for the current frame.
void onUpdate(float deltaTime)
{
if(gameHasFocus())
{
drawText(vector2(100,100), "Hello World!", "#FFFFFF", true, FONT_STANDARD, 20);
}
}
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).
int getDefaultFontSize(int fontNumber)
Get the default/native point size a font.
print("Default font sizes");
print("Standard: " + getDefaultFontSize(FONT_STANDARD));
print("Mono: " + getDefaultFontSize(FONT_MONO));
print("UAV: " + getDefaultFontSize(FONT_UAV));
void getFontHeight(int fontNumber, int fontSize)
Get the height of a font in pixels.
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);
drawPos.y += getFontHeight(font, fontSize);
}
}
}
void getTextWidth(string text, int fontNumber, int fontSize)
Get the width of a string of text in pixels.
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);
}
}
void drawRectangle(float x1, float y1, float x2, float y2, string colour, bool fill, float outlineThickness=2)
Draw a rectangle using absolute coordinates.
void onUpdate(float deltaTime)
{
if(gameHasFocus())
{
drawRectangle(10, 10, 110, 110, "#00000080", true);
}
}
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 drawRectangleWH(vector2 topLeftPos, vector2 totalSize, string colour, bool fill, float outlineThickness=2)
Draw a rectangle at the specified top-left position and width/height.
void onUpdate(float deltaTime)
{
if(gameHasFocus())
{
drawRectangleWH(vector2(10, 10), vector2(200, 100), "#00000080", true);
}
}
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 drawRectangleWHCentred(vector2 centrePos, vector2 totalSize, string colour, bool fill, float outlineThickness=2)
Draw a rectangle at the specified centre position and size.
void onUpdate(float deltaTime)
{
if(gameHasFocus())
{
drawRectangleWHCentred(vector2(60, 60), vector2(100, 100), "#00000080", true);
}
}
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 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.
void onUpdate(float deltaTime)
{
if(gameHasFocus())
{
drawRectangleRotated(vector2(60, 60), vector2(100, 100), , 45, "#00000080", true);
}
}
void drawTriangle(vector2 point1, vector2 point2, vector2 point3, string colour, float thickness=2)
Draw a triangle at the specified positions.
void onUpdate(float deltaTime)
{
if(gameHasFocus())
{
drawTriangle(vector2(100, 0), vector2(200, 200), vector2(0, 200), "#00FF00", false);
}
}
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.
void onUpdate(float deltaTime)
{
if(gameHasFocus())
{
drawCircleCentred(vector2(100, 0), vector2(200, 200), vector2(0, 200), "#00FF00", false);
}
}
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.
void onUpdate(float deltaTime)
{
if(gameHasFocus())
{
drawLine(vector2(0, 0), vector2(SCREEN_W - 1, SCREEN_H -1), "#FF0000");
}
}
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.
print(getSpriteNumber("objects\\arrow.spr"));
Returns -1 if the sprite file was not found.
Sprite numbers are local only.
int getSpriteFramesCount(int spriteNumber)
Get the number of frames in a sprite.
int spriteNumber = getSpriteNumber("ASCOUT.SPR");
print(getSpriteFramesCount(spriteNumber));
Returns 0 if the sprite file was not found.
vector2 getSpriteFrameSize(int spriteNumber, int frameNumber)
Get the size of a sprite frame in pixels.
int spriteNumber = getSpriteNumber("ASCOUT.SPR");
print(getSpriteFrameSize(spriteNumber, 0));
Returns 0,0 if the sprite file or frame was not found.
void drawSprite(vector2 pos, int spriteNumber, float angle=0, vector2 scale=vector2(1,1))
Draw a sprite to the screen UI.
int spriteArrow = 0;
float arrowSpriteAngle = 0;
void onWorldStart()
{
spriteArrow = getSpriteNumber("objects\\arrow.spr");
}
void onUpdate(float deltaTime)
{
if(gameHasFocus())
{
if(spriteArrow != -1)
{
arrowSpriteAngle += (deltaTime * 100);
drawSprite(getScreenSize() * 0.5, spriteArrow);
drawSprite(getScreenSize() * 0.3, spriteArrow, arrowSpriteAngle);
drawSprite(getScreenSize() * 0.7, spriteArrow, 360 - arrowSpriteAngle, vector2(3,3));
}
}
}
The sprite will animate automatically.
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.
int spriteArrow = -1;
void onWorldStart()
{
spriteArrow = getSpriteNumber("objects\\arrow.spr");
}
void onUpdate(float deltaTime)
{
if(gameHasFocus())
{
if(spriteArrow != -1)
{
if(mouseButtonDown(2))
{
drawSpriteFrame(mousePos(), spriteArrow, 0, 180, vector2(1, 1), "#FFFFFF80");
}
else
{
drawSpriteFrame(mousePos(), spriteArrow, 0);
}
}
}
}
Use to draw a single sprite frame without animation.
angle, scale and colour are optional.
int getImageNumber(string imageFilename)
Resolve a image filename to a sprite number.
print(getImageNumber("objects\\arrow01_01.png"));
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.
vector2 getImageSize(int imageNumber)
Get the size of an image in pixels.
int imageNumber = getImageNumber("objects\\arrow01_01.png");
print(getImageSize(imageNumber, 0));
Returns 0,0 if the image file was not found.
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.
int imageArrow = -1;
void onWorldStart()
{
imageArrow = getImageNumber("objects\\arrow01_01.png");
}
void onUpdate(float deltaTime)
{
if(gameHasFocus())
{
if(imageArrow != -1)
{
if(mouseButtonDown(2))
{
drawImage(mousePos(), imageArrow, 180, vector2(1, 1), "#FFFFFF80");
}
else
{
drawImage(mousePos(), imageArrow);
}
}
}
}
Use to draw a image directly name or draw an image that does not have a sprite.
angle, scale and colour are optional.
void drawCrtEffectOverlay()
Draw CRT effect overlay.
void onUpdate(float deltaTime)
{
drawCrtEffectOverlay();
}
Use to draw a CRT effect overlay with lines between pixels.
void drawScopeEffectOverlay()
Draw scope effect overlay.
void onUpdate(float deltaTime)
{
drawScopeOverlay(vector2(SCREEN_W * 0.5f, SCREEN_H * 0.5f), SCREEN_H * 0.5f);
}
Use to draw a black background with a hole to simulate looking down a scope.
void drawMonitorEffectOverlay()
Draw monitor effect overlay.
void onUpdate(float deltaTime)
{
drawMonitorEffectOverlay(getMousePos(), vector2(SCREEN_W * 0.5f, SCREEN_H * 0.5f));
}
Use to draw a black background with a rectangular hole to simulate looking at a monitor/screen.
Index