This page provides the top-level overview for the built-in LunarBasic functions, runtime helpers, and related constants currently available in the workspace.
These functions manage the graphics window, frame timing, pointer visibility, and screen-level drawing state.
| Function | Description |
|---|---|
| Cls | Clears the current frame's queued sprites. |
| Flip | Processes window events and presents the current frame. |
| FrameDelta | Returns the elapsed time in seconds for the last completed frame cycle between Flip calls. |
| Graphics | Creates or resizes the graphics window, sets the virtual resolution, and optionally enters borderless fullscreen mode when the third argument is True. |
| HidePointer | Hides the mouse pointer while it is over the graphics window client area. |
| MaxFps | Sets the maximum frame rate allowed by Flip. |
| MilliSecs | Returns the number of milliseconds since the machine was turned on. |
| ScaleWindow | Scales the physical window size relative to the virtual resolution created by Graphics. |
| ScreenHeight | Returns the current virtual screen height set by Graphics. |
| ScreenWidth | Returns the current virtual screen width set by Graphics. |
| SetAppTitle | Sets the application window title. |
| SetClsColor | Sets the clear color used when the frame is rendered. |
| SetDrawColor | Sets the color used by DrawRect, DrawFilledRect, and DrawLine. The alpha component defaults to 255. |
| SetTextColor | Sets the color used for subsequent DrawText calls. |
| SetVSync | Enables or disables vertical sync for future Flip calls. |
| ShowPointer | Shows the mouse pointer while it is over the graphics window client area. |
These functions load assets, control render state, and queue drawing commands for the screen or the active buffer.
| Function | Description |
|---|---|
| ClearBufferTarget | Stops drawing into the active off-screen buffer and returns drawing to the main screen. |
| ClearClipRegion | Removes the active clip region so subsequent drawing can affect the full screen or active buffer again. |
| CreateBuffer | Creates an off-screen buffer image and returns an integer handle for it. |
| CreateImage | Creates a custom image with immutable dimensions and returns an integer handle. |
| DrawBuffer | Draws a previously rendered buffer at the given position. |
| DrawBufferSub | Draws a rectangular source region from a previously rendered buffer. |
| DrawFilledRect | Queues a filled rectangle using the current draw color. |
| DrawImage | Queues an image so its hotspot is drawn at the given position. |
| DrawImageEx | Queues an image with hotspot-centered rotation and optional uniform scaling. |
| DrawImageSub | Queues a rectangular source region from an image so the image hotspot is drawn at the given position. |
| DrawLine | Queues a one-pixel line using the current draw color. |
| DrawNineSlice | Queues a nine-slice image using the full image and the supplied border margins, positioned by the image hotspot. |
| DrawRect | Queues an outlined rectangle using the current draw color. |
| DrawSprite | Queues a sprite-sheet frame so the sprite hotspot is drawn at the given position. |
| DrawSpriteEx | Queues a sprite-sheet frame with hotspot-centered rotation and optional uniform scaling. |
| DrawText | Queues text to be drawn using a loaded font atlas. |
| FreeBuffer | Releases a previously created off-screen buffer handle. |
| FreeImage | Releases a previously loaded image handle. |
| FreeSprite | Releases a previously loaded sprite handle. |
| GetImageHotspotX | Returns the image hotspot X coordinate in source pixels. |
| GetImageHotspotY | Returns the image hotspot Y coordinate in source pixels. |
| GetSpriteHotspotX | Returns the sprite hotspot X coordinate in source pixels. |
| GetSpriteHotspotY | Returns the sprite hotspot Y coordinate in source pixels. |
| ImageHeight | Returns the source image height in pixels. |
| ImageWidth | Returns the source image width in pixels. |
| LoadFont | Loads a font texture and character map and returns an integer font handle. |
| FreeFont | Releases a previously loaded font handle. |
| LoadImage | Loads an image and returns an integer handle. |
| LoadImagePixels | Reads image pixels into an Integer array using ARGB format. |
| LoadSprite | Loads a sprite sheet and returns an integer handle. |
| SetBufferTarget | Redirects subsequent drawing commands into an off-screen buffer. |
| SetClipRegion | Restricts subsequent drawing to the specified rectangular region. |
| SetDefaultBlendMode | Sets the default blend mode for images and sprites. |
| SetDefaultScaleMode | Sets the default scale mode for images and sprites. |
| SetImageBlendMode | Sets the blend mode for an image handle. |
| SetImageColorMod | Sets per-image color modulation values. |
| SetImageHotspot | Sets the hotspot for an image handle. |
| SetImageScaleMode | Sets the scale filtering mode for an image handle. |
| SetSpriteBlendMode | Sets the blend mode for a sprite handle. |
| SetSpriteColorMod | Sets per-sprite color modulation values. |
| SetSpriteHotspot | Sets the hotspot for a sprite handle. |
| SetSpriteScaleMode | Sets the scale filtering mode for a sprite handle. |
| SetTextAlign | Sets alignment mode used by DrawText. |
| UpdateImagePixels | Updates an image from an ARGB Integer array and uploads it to the renderer. |
These functions load and control background music, sound effects, and video playback.
| Function | Description |
|---|---|
| FreeSfx | Releases a previously loaded sound-effect handle. |
| LoadSfx | Loads a sound effect and returns an integer handle. |
| LoopSfx | Starts a sound effect and controls whether playback loops. |
| PauseSfx | Pauses playback of a sound effect. |
| PlayBGM | Starts background music playback, with looping enabled by default. |
| PlaySfx | Plays a sound effect once. |
| PlayVideo | Plays a video file, optionally allowing the user to skip playback. |
| ResumeSfx | Resumes a paused sound effect. |
| SetBgmVolume | Sets background music volume in the 0.0 to 1.0 range. |
| SetSfxPan | Sets stereo pan for a sound effect. |
| SetSfxSpeed | Sets playback speed for a sound effect. |
| SetSfxVolume | Sets volume for a sound effect in the 0.0 to 1.0 range. |
| StopBGM | Stops background music playback. |
| StopSfx | Stops playback of a sound effect. |
These functions open files, read and write typed values, and query file state.
| Function | Description |
|---|---|
| CloseFile | Closes an open file handle. |
| DeleteFile | Deletes the named file and returns True when the deletion succeeds. |
| DebugPrint | Writes a line of text to runtime diagnostics output. |
| EndOfFile | Returns True when a text file has no more lines to read. |
| FileExists | Returns True when the named file exists. |
| FileSeek | Moves the current file position to an absolute byte offset from the start of the file. |
| FileSize | Returns the total size of the open file in bytes. |
| FileTell | Returns the current file position in bytes from the start of the file. |
| OpenFile | Opens a file for reading, or read/write access when the optional second argument is True, and returns an integer file handle. |
| ReadByte | Reads one unsigned byte from the current file position and returns it as an Integer. |
| ReadDouble | Reads one 64-bit floating-point value from the current file position. |
| ReadDword | Reads one 32-bit unsigned integer from the current file position and returns it as an Integer. |
| ReadFloat | Reads one 32-bit floating-point value from the current file position. |
| ReadLine | Reads one text line, supports \r, \n, and \r\n endings, and strips invisible control characters from the returned text. |
| ReadWord | Reads one 16-bit unsigned integer from the current file position and returns it as an Integer. |
| SetCurrentDir | Changes the current working directory used by relative file paths. |
| WriteByte | Writes the low 8 bits of an Integer value at the current file position. |
| WriteDouble | Writes one 64-bit floating-point value at the current file position. |
| WriteDword | Writes the low 32 bits of an Integer value at the current file position. |
| WriteFloat | Writes one 32-bit floating-point value at the current file position. |
| WriteLine | Writes a string followed by a new line at the current file position. |
| WriteWord | Writes the low 16 bits of an Integer value at the current file position. |
These functions read controller, keyboard, and mouse state in the current frame, plus mouse position and managed text input buffer workflow for in-game text entry.
| Function | Description |
|---|---|
| ClearTextInput | Clears the current tracked text input buffer to an empty string. |
| GetTextInput$ | Returns the currently tracked text input buffer. |
| JoyAxis# | Returns the current value of a controller axis. |
| JoyButtonDown | Returns True while the specified controller button is currently pressed. |
| JoyButtonHit | Returns True on the frame when the specified controller button is pressed. |
| JoyConnected | Returns True when the specified controller slot is connected. |
| JoyCount | Returns the number of controller slots supported by the runtime. |
| JoyName$ | Returns the display name for a connected controller slot. |
| KeyDown | Returns True while the specified key is currently pressed. |
| KeyHit | Returns True on the frame when the specified key is pressed. |
| MouseButton | Returns True while the specified mouse button is currently pressed. |
| MouseHit | Returns True on the frame when the specified mouse button is pressed. |
| MouseX | Returns the current mouse X position mapped into the virtual screen coordinate space. |
| MouseY | Returns the current mouse Y position mapped into the virtual screen coordinate space. |
| SetTextInput | Replaces the tracked text input buffer with the supplied string, truncated to 2048 characters. |
| StartTextInput | Starts tracking keyboard text entry into the runtime text buffer. |
| StopTextInput | Stops tracking keyboard text entry while preserving the current text buffer contents. |
This feature loads Tiled maps into built-in LunarBasic object types so map data can be accessed with normal fields and arrays.
Legacy handle-based Tiled query functions were removed.
| Function | Description |
|---|---|
| LoadTiledMap | Loads a Tiled map and returns a TiledMap object. |
These functions create derived strings, search text, and convert values to and from text.
| Function | Description |
|---|---|
| AppDataDir$ | Returns the user-local application data folder path. |
| AppDir$ | Returns the folder containing the running executable. |
| ChrPos | Returns the first zero-based index of a character, or -1 when it is not found. |
| CurrentDir$ | Returns the current working directory path. |
| DesktopDir$ | Returns the current user's desktop folder path. |
| DocumentsDir$ | Returns the current user's documents folder path. |
| FileDir$ | Returns the directory portion of a path. |
| FileExt$ | Returns the extension portion of a file path without the dot. |
| FileName$ | Returns the file name portion of a path. |
| HomeDir$ | Returns the current user's home folder path. |
| Instr | Searches for one string inside another beginning at a 1-based offset. |
| Left$ | Returns the leftmost characters from a string. |
| Lower$ | Returns a lowercase copy of a string. |
| Mid$ | Returns a substring using a 1-based offset and a character count. |
| PathCombine$ | Combines a base path with an additional segment. |
| Replace$ | Returns a string with all matching occurrences replaced. |
| Right$ | Returns the rightmost characters from a string. |
| StripExt$ | Returns a path with its file extension removed. |
| Str | Converts a numeric value to its string form. |
| StringLen | Returns the number of characters in a string. |
| StrPos | Returns the first zero-based index of a string match, or -1 when it is not found. |
| TempDir$ | Returns the system temporary folder path. |
| ToBoolean | Converts a string to a Boolean using True, False, 1, or 0. |
| ToDouble | Converts a string to a double-precision numeric value. |
| ToFloat | Converts a string to a single-precision floating-point value. |
| ToInt | Converts a string to an integer value. |
| Trim$ | Removes leading and trailing whitespace from a string. |
| Upper$ | Returns an uppercase copy of a string. |
These helpers provide common numeric operations used by gameplay and rendering code.
| Function | Description |
|---|---|
| Ceil | Rounds the value up to the next whole integer. |
| Floor | Rounds the value down to the next whole integer. |
| Lerp | Linearly interpolates between the start and end values using the given amount. |
| Max | Returns the larger of the two values. |
| Min | Returns the smaller of the two values. |
| Pow | Raises the base value to the given exponent. |
| Rand | Returns a random integer in the requested inclusive range. |
| Rnd! | Returns a random Double in the requested range. |
| RndDouble! | Returns a random Double between 0.0 and 1.0. |
| RndFloat# | Returns a random Float between 0.0 and 1.0. |
| RndSeed | Creates a random seed value. |
| Round | Rounds the value to the nearest whole integer. |
| SeedRnd | Seeds the runtime random number generator. |
| Slerp | Smoothly interpolates between the start and end values using cosine easing. |
| Sqrt | Returns the square root of the value. |
These names are reserved built-in commands in LunarBasic.
| Function | Description |
|---|---|
| ArrayLen | Returns either the total element count of an array or the length of a specific zero-based dimension. |
| Free | Releases a user-defined object that was previously created with New. |
| Resize | Changes the length of a one-dimensional array while keeping the elements that still fit. |
| Terminate | Immediately exits the program, optionally using a supplied integer exit code. |
These built-in constants are available directly in your LunarBasic code and are commonly used with the functions listed above.
| Constant Set | Description |
|---|---|
| Blend Mode Constants | Controls how image colors are blended with the background when drawn. |
| Keyboard Constants | Identifies individual keyboard keys such as Escape, arrows, letters, digits, and function keys. |
| Scale Mode Constants | Controls how images are filtered when they are scaled. |
For focused examples, open the detail page for a specific function. For a larger sample, see related entries such as Graphics, DrawImage, Flip, and KeyDown.