0% found this document useful (0 votes)
58 views12 pages

MicroScript API Cheatsheet

The document is an API cheatsheet for microStudio, detailing various functions and methods for drawing on the screen, handling input from keyboards, gamepads, touch, and mouse, as well as managing assets and system operations. It includes specific commands for drawing shapes, images, and text, along with color settings and blending modes. Additionally, it provides information on loading assets and system functionalities such as time and language retrieval.

Uploaded by

praneshvisakan25
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views12 pages

MicroScript API Cheatsheet

The document is an API cheatsheet for microStudio, detailing various functions and methods for drawing on the screen, handling input from keyboards, gamepads, touch, and mouse, as well as managing assets and system operations. It includes specific commands for drawing shapes, images, and text, along with color settings and blending modes. Additionally, it provides information on loading assets and system functionalities such as time and language retrieval.

Uploaded by

praneshvisakan25
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

en API cheatsheet · pmgl/microstudio Wiki

[Link]/pmgl/microstudio/wiki/en-API-cheatsheet

API cheatsheet

Drawing

screen

[Link] The current width of the screen in microStudio units

[Link] The current height of the screen in microStudio


units

[Link]( [color] ) Clears the screen (fills it in black, or in the optional


color argument passed)

[Link]( color ) Sets the color for subsequent drawing operations.

[Link]( opacity ) Sets the opacity of subsequent drawing operations,


in the range [0 .. 1]

[Link]( blending ) Sets the blending mode for subsequent drawing


operations

[Link]( x1, y1, x2, y2, color1, Sets a linear gradient for subsequent drawing
color2 ) operations

[Link]( x, y, radius, color1, Sets a radial gradient for subsequent drawing


color2 ) operations

[Link]( font_name ) Sets the name of the font to use for subsequent text
drawing operations

[Link]( tx, ty ) Translates the screen coordinates

[Link]( sx, sy ) Scales the screen coordinates

[Link]( rotation ) Rotates the screen coordinates

[Link]( x, y ) Sets the anchor (pivot) point for drawing elements.


Range for x and y: [-1 .. 1]

[Link]( rotation ) Sets a rotation angle for drawing elements, around


their anchor point

[Link]( x, y ) Sets the drawing scale for elements, on their x-axis


and y-axis

[Link]( x, y, width, height [,color] ) Draws a filled rectangle

[Link]( x, y, width, height, roundness Draws a filled rounded rectangle


[,color] )

[Link]( x, y, width, height [,color] ) Draws a filled round shape (ellipse or circle
depending on your arguments)

1/12
[Link]( x, y, width, height [,color] ) Draws a rectangle outline

[Link]( x, y, width, height, Draws a rounded rectangle outline


roundness [,color] )

[Link]( x, y, width, height [,color] ) Draws a round shape outline (ellipse or circle
depending on your arguments)

[Link]( name, x, y, width [,height] ) Draws a sprite at given coordinates

[Link]( name, px, py, pw, ph, x, y, Draws an area of this sprite at given coordinates
width [,height] )

[Link]( image, x, y, width [,height] ) Draws an image at given coordinates

[Link]( image, px, py, pw, ph, x, y, Draws an area of the image at given coordinates
width [,height] )

[Link]( name, x, y, width [,height] ) Draws a map at given coordinates

[Link]( pixelated ) Sets how sprites or images must be rendered:


pixelated or smoothed

[Link]( text, x, y, size [,color] ) Draws text at given coordinates with given size

[Link]( text, x, y, size [,color] ) Draws text outline at given coordinates with given
size

[Link]( text, size ) Returns the width of the given text when drawn at
given size

[Link]( width ) Sets the width of lines for subsequent drawing


operations

[Link]( [2,4] ) Sets the line style, as an array of lines and gaps

[Link]( x1, y1, x2, y2 ) Draws a line

[Link]( x1, y1, x2, y2, x3, y3 ... The coordinates can also be passed as an array
[,color])

[Link]( x1, y1, x2, y2, x3, y3 ... The coordinates can also be passed as an array
[,color])

[Link]( x1, y1, x2, y2, x3, y3 ... [,color]) The coordinates can also be passed as an array

[Link]( x, y, radius, start_angle, Draws an arc of a circle


end_angle, counter_clockwise [,color])

[Link]( x, y, radius, start_angle, end_angle, Fills an arc of a circle


counter_clockwise [,color])

[Link]( x1, y1, cp1x, cp1y, x2, y2, You can pass as many points as needed ; you can
... [,color]) pass all the points as an array

[Link]( x1, y1, cp1x, cp1y, cp2x, You can pass as many points as needed ; you can
cp2y, x2, y2, ... [,color]) pass all the points as an array

[Link]( visible ) Sets whether the mouse cursor should be visible

[Link]( fontname ) Initiates the loading of a font

[Link]( fontname ) Checks whether the font is ready to use

colors

2/12
"rgb(128,160,196)"

"rgba(128,160,196,0.5)"

"#8090A0"

"hsl(200,50%,50%)"

"hsla(200,50%,50%,0.25)"

blending modes

"normal" "additive" "source-out" "source-atop" "destination-over"

"destination-in" "destination-out" "destination-atop" "lighter" "copy"

"xor" "multiply" "screen" "overlay" "darken"

"lighten" "color-dodge" "color-burn" "hard-light" "soft-light"

"difference" "exclusion" "hue" "saturation" "color"

"luminosity" "source-over" "source-in"

See [Link]
US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation

Inputs / Control

keyboard

keyboard.A keyboard.B [Link] [Link]

[Link].A [Link].B [Link] [Link]

[Link].A [Link].B [Link] [Link]

gamepad

gamepad.A gamepad.B gamepad.X

gamepad.Y [Link] [Link]

[Link] [Link] [Link]

[Link] gamepad.DPAD_UP gamepad.DPAD_DOWN

gamepad.DPAD_LEFT gamepad.DPAD_RIGHT [Link]

[Link] [Link] [Link]

3/12
[Link] [Link] gamepad.LEFT_STICK_UP

gamepad.LEFT_STICK_DOWN gamepad.LEFT_STICK_LEFT gamepad.LEFT_STICK_RIGHT

gamepad.RIGHT_STICK_UP gamepad.RIGHT_STICK_DOWN gamepad.RIGHT_STICK_LEFT

gamepad.RIGHT_STICK_RIGHT gamepad.LEFT_STICK_ANGLE gamepad.LEFT_STICK_AMOUNT

gamepad.RIGHT_STICK_ANGLE gamepad.RIGHT_STICK_AMOUNT

[Link].A (B, X, Y ...) [Link].A (B, X, Y ...)

gamepad[0].A (B, X, Y ...) gamepad[1].A (B, X, Y ...)

gamepad[2].press.A (B, X, Y ...) gamepad[3].release.A (B, X, Y ...)

touch

[Link]

[Link]

[Link]

touch.x

touch.y

[Link] list of all current active touches

mouse

mouse.x current mouse pointer position x

mouse.y current mouse pointer position y

[Link] 1 if any mouse button is pressed, else 0

[Link] 1 if left mouse button is pressed, else 0

[Link] 1 if middle mouse button is pressed, else 0

[Link] 1 if right mouse button is pressed, else 0

[Link] value can be 1 (up), -1 (down) or 0

[Link] 1 if any mouse button was just first pressed

[Link] 1 when the last active mouse button was just released

Assets

asset_manager

4/12
asset_manager.loadFont( path ) Initiates loading of the font asset

asset_manager.loadImage( path, Loads image, returns a loader object and calls callback when ready
callback )

asset_manager.loadModel( path, Loads 3D model, returns a loader object and calls callback when
scene, callback ) ready

asset_manager.loadJSON( path, Loads JSON as microScript object, returns a loader object and calls
callback ) callback when ready

asset_manager.loadText( path, Loads TXT as microScript string, returns a loader object and calls
callback ) callback when ready

asset_manager.loadCSV( path, Loads CSV as microScript string, returns a loader object and calls
callback ) callback when ready

asset_manager.loadMarkdown( Loads .md file as microScript string, returns a loader object and calls
path, callback ) callback when ready

asset_manager.wasmInstance( Creates an instance of a WebAssembly module, returns a loader


path, callback ) object and calls callback when ready

Misc

system

member description

[Link]() Returns the system time in milliseconds (time elapsed since January 1st 1970)

[Link] Returns the language of the user

[Link] Allows to check which input methods are available on the user's system

[Link] Returns 1 if the user's system has a keyboard

[Link] Returns 1 if the user's system has a mouse pointer

[Link] Returns 1 if the user's system has a touch screen

[Link] Returns 1 if there is at least one plugged in, active gamepad

[Link]( text, Prompts the user to enter text and calls callback( ok, text )
callback)

[Link]( text ) Displays a message to the user, in a dialog box

[Link]() Pauses execution. Execution can be resumed with the "play" button in the
microStudio interface

[Link]() Exits the program

[Link] Set to 1 by default, can be set to 0 to make the threading system non-
preemptive

[Link] Holds a list of all the active threads (running or paused).

system.update_rate Writable call rate of update(), example: system.update_rate = 120

5/12
storage

[Link]( name, value )

[Link]( name, value )

Images

Create Image

image = new Image( width, height )

Draw on image

Note: the default coordinates system for drawing into an image differs a lot from drawing on screen.
When drawing on an image, the default unit is one pixel ; the origin is set to the upper left corner of the
image. The y-axis is oriented downwards.

If you wish to create an image preconfigured with the centered, y-axis up coordinate system, you can
do so by adding true as third parameter to the Image constructor:

image = new Image( width, height , true )

member description

[Link] Width of the image in pixels

[Link] Height of the image in pixels

[Link]( [color] ) Clears the image

[Link]( x, y, r, g, b) Sets pixel color

[Link]( x, y, r, g, b, a) Sets pixel color and opacity

[Link]( x, y [,result]) Returns pixel color as an object with R, G and B


components

[Link]( x, y [,result]) Returns pixel color as an object with R, G, B and A


components

[Link]( color ) Sets the color for subsequent drawing operations.

[Link]( opacity ) Sets the opacity of subsequent drawing operations,


in the range [0 .. 1]

[Link]( blending ) Sets the blending mode for subsequent drawing


operations

[Link]( x1, y1, x2, y2, color1, Sets a linear gradient for subsequent drawing
color2 ) operations

6/12
member description

[Link]( x, y, radius, color1, Sets a radial gradient for subsequent drawing


color2 ) operations

[Link]( font_name ) Sets the name of the font to use for subsequent text
drawing operations

[Link]( tx, ty ) Translates the image coordinates

[Link]( sx, sy ) Scales the image coordinates

[Link]( rotation ) Rotates the image coordinates

[Link]( x, y ) Sets the anchor (pivot) point for drawing elements.


Range for x and y: [-1 .. 1]

[Link]( rotation ) Sets a rotation angle for drawing elements, around


their anchor point

[Link]( x, y ) Sets the drawing scale for elements, on their x-axis


and y-axis

[Link]( x, y, width, height [,color] ) Draws a filled rectangle

[Link]( x, y, width, height, roundness Draws a filled rounded rectangle


[,color] )

[Link]( x, y, width, height [,color] ) Draws a filled round shape (ellipse or circle
depending on your arguments)

[Link]( x, y, width, height [,color] ) Draws a rectangle outline

[Link]( x, y, width, height, Draws a rounded rectangle outline


roundness [,color] )

[Link]( x, y, width, height [,color] ) Draws a round shape outline (ellipse or circle
depending on your arguments)

[Link]( name, x, y, width [,height] ) Draws a sprite at given coordinates

[Link]( name, px, py, pw, ph, x, y, Draws an area of this sprite at given coordinates
width [,height] )

[Link]( image, x, y, width [,height] ) Draws an image at given coordinates

[Link]( image, px, py, pw, ph, x, y, Draws an area of the image at given coordinates
width [,height] )

[Link]( name, x, y, width [,height] ) Draws a map at given coordinates

[Link]( pixelated ) Sets how sprites or images must be rendered:


pixelated or smoothed

[Link]( text, x, y, size [,color] ) Draws text at given coordinates with given size

[Link]( text, x, y, size [,color] ) Draws text outline at given coordinates with given
size

[Link]( text, size ) Returns the width of the given text when drawn at
given size

[Link]( width ) Sets the width of lines for subsequent drawing


operations

[Link]( [2,4] ) Sets the line style, as an array of lines and gaps

7/12
member description

[Link]( x1, y1, x2, y2 ) Draws a line

[Link]( x1, y1, x2, y2, x3, y3 ... The coordinates can also be passed as an array
[,color])

[Link]( x1, y1, x2, y2, x3, y3 ... The coordinates can also be passed as an array
[,color])

[Link]( x1, y1, x2, y2, x3, y3 ... [,color]) The coordinates can also be passed as an array

[Link]( x, y, radius, start_angle, Draws an arc of a circle


end_angle, counter_clockwise [,color])

[Link]( x, y, radius, start_angle, end_angle, Fills an arc of a circle


counter_clockwise [,color])

[Link]( x1, y1, cp1x, cp1y, x2, y2, You can pass as many points as needed ; you can
... [,color]) pass all the points as an array

[Link]( x1, y1, cp1x, cp1y, cp2x, You can pass as many points as needed ; you can
cp2y, x2, y2, ... [,color]) pass all the points as an array

Save image

[Link]( image, name Saves the image to the PC. Format can be set to "png" or "jpg" and
[,format [, quality ]]) quality (jpg only) in the range [0 .. 1]

Sprites

Create and modify

sprite = sprites["icon"] Default global object sprites retains all project sprites

[Link] = 10 Change the animation speed in case of an animated sprite

[Link]( 10 ) Change the animation speed while preserving the current phase

[Link](0) Sets the current animation frame

image = [Link][0] Get the Image object of the first (or only) sprite frame

[Link]( image ) Add a new frame to this sprite

Maps

Create Map

map = new Map( width_in_tiles, height_in_tiles, tile_pixel_width, tile_pixel_height )

8/12
Map functions

[Link]( x, y )

[Link]( x, y , "sprite" )

[Link]( x, y , "tilemap:4,6" )

Sounds

beeps

[Link]( "C4 E G C5 E G" )

[Link]( "volume 50 span 50 tempo 240 loop 4 C4 E G C5 E G end" )

[Link]()

play sounds

sound = [Link]( "mysound" Starts playing the sound "mysound" and returns a controller
) object

control sound playback

[Link]( volume ) sets the volume for the playback of the sound

[Link]( pitch ) sets the pitch for the playback of the sound

[Link]( pan ) sets the pan of the playing sound

[Link]() returns the duration of the sound in seconds

[Link]() stops the playback of the sound

play music

music = [Link]( "mymusic" ) Starts playing the music "mymusic" and returns a controller object

control music playback

[Link]( volume )

9/12
[Link]()

[Link]()

[Link]() in seconds

[Link]() in seconds

[Link]( position ) in seconds

create Sound

sound = new Sound( channels, length, sampleRate ) Creates a sound object

[Link]( channel, index, value ) Writes sample data

[Link]( channel, index ) Reads sample data

[Link]( [ volume, pitch, pan, loop ])

File API

load file

with callback

[Link]( ["png","jpg"] , function( file_list )


for file in file_list
print([Link])
end
end)

without callback

[Link]( ["png","jpg"] )

(...)

update = function()
if [Link] then
for file in [Link]
print( [Link] )
end
end
end

file dropped

10/12
update = function()
if [Link] then
for file in [Link]
print( [Link] )
end
end
end

save file

[Link]( obj, name ) saves your object as a json file

[Link]( image, name )

[Link]( sound, name )

Project access API

The project access API is only available when the project is running within the microStudio editor. You can
check the availability with if [Link] then ...

list project files

[Link]( "source", function( list, error) print(list) end )

[Link]( "sprites/folder1", function( list, error) print(list) end )

[Link]( "maps", function( list, error) print(list) end )

[Link]( "sounds", function( list, error) print(list) end )

[Link]( "music", function( list, error) print(list) end )

[Link]( "assets", function( list, error) print(list) end )

read project files

[Link]( "source/main", function(result, error) print(result) end )

[Link]( "sprites/icon", function( sprite, error) [Link](sprite,0,0,50) end )

[Link]( "maps/folder/map1", function( map, error) [Link](map,0,0,320,200)


end )

[Link]( "sounds/fx/blast", function(sound, error) [Link]() end )

[Link]( "music/song", function(sound, error) [Link]() end )

[Link]( "assets/textfile", function(text, error) print(text) end )

[Link]( "assets/image_file", function( image, error) [Link](image,0,0,200)


end )

[Link]( "assets/json_file", function( obj, error) print(obj.x) end )

11/12
write project files

[Link]( "source/generated/src1", string, 0, function(result, error) print(result) end )

[Link]( "sprites/generated/sprite1", sprite, 0, function(result, error) print(result) end )

[Link]( "sprites/generated/map1", map, 0, function(result, error) print(result) end )

[Link]( "sounds/generated/sound1", sound, 0, function(result, error) print(result) end )

[Link]( "music/generated/music1", sound, 0, function(result, error) print(result) end )

[Link]( "assets/generated/textfile", string, object ext = "txt" end, function(result, error)


print(result) end )

[Link]( "assets/generated/jsonfile", obj, object ext = "json" end, function(result, error)


print(result) end )

[Link]( "assets/generated/imagefile", image, object ext = "jpg" end, function(result,


error) print(result) end )

delete project file

[Link]( "sprites/sprite1", function(result, error) print(result) end )

12/12

Common questions

Powered by AI

Gamepad and touch input methods in microStudio extend traditional keyboard and mouse control mechanisms by offering direct interaction capabilities that align with modern device interfaces. Gamepads provide physical button inputs and analogue directional controls captured by microStudio's gamepad API, enhancing the range of control schemes possible for games and applications, as seen with gamepad.A or gamepad.LEFT_STICK_AMOUNT. Touch inputs capture gestures like touch.press and touch.x, allowing for more intuitive and natural user interactions on touch-capable devices. These integrations enable richer interaction paradigms, enhancing user engagement and accommodating diverse platform capabilities .

In microStudio, the `setTranslation(tx, ty)` method can be applied both for screen and image elements to shift the coordinate system by a translation vector (tx, ty). This method allows elements to be drawn as if the origin has moved to a new location, facilitating various complex layout designs and creating animations without altering the actual positions of elements themselves. It is significant for graphical manipulation as it changes the perceived position of graphics on the display, making it easier to move objects together, realign graphics dynamically, or set up complex scenes .

In microStudio, drawing polygons and arcs both utilize coordinates but differ in their requirements and implications. A polygon, when drawn, expects a simple list of vertex points, which can be passed as an array to form a continuous line closed off between the starting and ending points. This allows creation of straight-edged, multi-sided shapes. An arc, however, necessitates additional parameters such as radius, start and end angles, and potentially a counter-clockwise flag, indicating a needed calculation based on circular mathematics rather than just straight lines. The distinction matters as it highlights the complexity of rendering curves versus straight lines and impacts how developers plan to use these primitives in their graphics work, potentially affecting performance and visual accuracy .

Linear and radial gradients in microStudio are applied using `setLinearGradient` and `setRadialGradient` functions for both screen and image drawing operations. Linear gradients transition colors along a line between two points, establishing gradation along a directed path. Radial gradients extend colors from a central point outward, forming concentric fill patterns. These are vital in graphic design as they facilitate the creation of sophisticated color transitions, adding depth and visual interest without needing multiple drawn elements. They enable designers to simulate lighting effects, create backgrounds with dimensionality, and offer nuanced texturing that elevates graphical output .

The `system.preemptive` setting in microStudio governs whether the threading system operates in a preemptive or cooperative manner. By default, it is set to 1, indicating a typical preemptive multitasking system where threads are managed and switched automatically by the system scheduler. Setting it to 0 changes it to non-preemptive, where the system relies on threads to yield control back voluntarily. Adjusting it can dramatically affect program execution, influencing performance optimization. With non-preemptive multitasking, you have increased control over execution order and timing but with an added responsibility to handle yielding properly to prevent any single thread from hogging system resources .

Blending modes in microStudio, such as 'normal', 'additive', 'multiply', 'screen', and others, determine how the colors of one object combine with colors beneath it. For instance, 'additive' blending adds the color channel values, enhancing brightness and creating glow effects, whereas 'multiply' blends by multiplying the color values, often used for shadow impacts. These modes are effectively utilized for creating various visual effects by manipulating how elements are visually composed, enabling effects like transparency, texture overlay, shading, and more elaborate visual dynamics in animations and drawings .

The `asset_manager.loadFont` function in microStudio initiates the loading of a font asset from a specified path. The purpose is to ensure that font resources are prepared and available for text rendering operations before they are needed in the visual pipeline. This process is critical because it involves asynchronous loading, where readiness is confirmed via the `isFontReady` method before actually using the font, crucial for performance especially in graphics-intensive applications. It prevents degradation in rendering performance by ensuring fonts are preloaded, avoiding runtime delays that would occur if font assets were pulled during frame updates .

MicroStudio allows manipulation of sprite animation through mechanisms like setting the frames per second with `sprite.setFPS` and directly controlling frames via `sprite.setFrame`. These provide a framework for dynamically adjusting the speed and phases of sprite animations, influencing how visual sequences are choreographed in the animation pipeline. By adjusting FPS, developers can alter the tempo of animations globally or for individual sprites, crucial for achieving desired pacing and responsiveness in interactive applications. The direct frame control allows precise handling of animation states, enabling complex animation logic such as looping and transitions between different sets of animations .

The system project API in microStudio facilitates operations like listing, reading, writing, and deleting project files directly from the microStudio editor. This API allows for dynamic file manipulation without external tools, streamlining workflow within the integrated development environment. The availability toggle is significant as it indicates whether the project is actively running within the editor context, ensuring file operations are only attempted when supported, preventing runtime errors and data inconsistency. This toggle allows developers to write scripts that adapt to different execution environments, thereby enforcing integrity in file management processes .

In microStudio, handling mouse input data significantly impacts interactivity features, particularly utilizing properties like `mouse.x` and `mouse.y`. These properties indicate the current position of the mouse pointer, allowing applications to react to user movements and clicks, crucial for real-time interaction in applications such as games and UI controls. By tracking these coordinates, developers can implement features like drag-and-drop, hover effects, and responsive navigation, greatly enhancing user engagement and usability through intuitive feedback mechanisms .

You might also like