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