Global

Methods

AutoMidHandle(valueopt)

Enables or disables automatic centering of the handle for all subsequently loaded images.
Parameters:
Name Type Attributes Default Description
value boolean <optional>
false True to enable auto-mid-handling, false to disable.
Source:

BackBuffer() → {null}

Returns a token representing the main screen buffer, for use with `SetBuffer`.
Source:
Returns:
Type
null

ChangeDir(path) → {boolean}

Changes the current working directory.
Parameters:
Name Type Description
path string The path to the new directory.
Source:
Returns:
True on success.
Type
boolean

ChannelPlaying(channelHandle) → {boolean}

Checks if a sound is still playing on a specific channel.
Parameters:
Name Type Description
channelHandle number The channel handle.
Source:
Returns:
Type
boolean

ChannelVolume(channelHandle, volume)

Changes the volume of a currently playing sound on a specific channel.
Parameters:
Name Type Description
channelHandle number The channel handle.
volume number The new volume (0.0 to 1.0).
Source:

CloseDir(handle)

Closes an open directory handle.
Parameters:
Name Type Description
handle number The directory handle to close.
Source:

CloseFile(handle)

Closes an open file handle.
Parameters:
Name Type Description
handle number The file handle to close.
Source:

Cls()

This command will wipe the canvas clean of any graphics or text present and reset the canvas back to the color defined in the ClsColor command
Source:

ClsColor(redopt, greenopt, blueopt)

This changes the color for subsequent CLS calls. Use this command when you need CLS to 'clear' the screen with some other color than black.
Parameters:
Name Type Attributes Default Description
red number <optional>
0 The red component (0-255).
green number <optional>
0 The green component (0-255).
blue number <optional>
0 The blue component (0-255).
Source:

Color(red, green, blue)

This command sets the drawing color (using RGB values) for all subsequent drawing commands (Line, Rect, Text, etc.).
Parameters:
Name Type Description
red number The red component (0-255).
green number The green component (0-255).
blue number The blue component (0-255).
Source:

CopyFile(sourcePath, destPath) → {boolean}

Copies a file from a source path to a destination path.
Parameters:
Name Type Description
sourcePath string The path of the file to copy.
destPath string The destination path for the new file.
Source:
Returns:
True on success.
Type
boolean

CopyImage(img) → {object}

Creates a copy of an image.
Parameters:
Name Type Description
img object The image handle to copy.
Source:
Returns:
A new image handle.
Type
object

CreateDir(path) → {boolean}

Creates a new directory.
Parameters:
Name Type Description
path string The path of the directory to create.
Source:
Returns:
True on success.
Type
boolean

CreateImage(width, height) → {object}

Creates a new, blank, drawable image.
Parameters:
Name Type Description
width number The width of the new image.
height number The height of the new image.
Source:
Returns:
An image handle.
Type
object

CreateType(templateObject) → {function}

Emulates BlitzBasic's Type/New functionality by creating a factory function for a specific object structure.
Parameters:
Name Type Description
templateObject object An object defining the fields and default values for the new type.
Source:
Returns:
A function that, when called, returns a new object based on the template.
Type
function
Example
const NewBullet = jbb.CreateType({ x: 0, y: 0, speed: 8, active: true });
let myBullet = NewBullet(); // myBullet is now { x: 0, y: 0, speed: 8, active: true }

CurrentDir() → {string}

Returns the current working directory path.
Source:
Returns:
Type
string

DeleteDir(path) → {boolean}

Deletes an empty directory.
Parameters:
Name Type Description
path string The path of the directory to delete.
Source:
Returns:
True on success.
Type
boolean

DeleteFile(path) → {boolean}

Deletes a file.
Parameters:
Name Type Description
path string The path of the file to delete.
Source:
Returns:
True on success.
Type
boolean

DownloadFile(path, downloadNameopt) → {boolean}

Triggers a browser download for a file stored in the virtual file system.
Parameters:
Name Type Attributes Description
path string The path of the file to download.
downloadName string <optional>
Optional. The name for the downloaded file.
Source:
Returns:
True if the download was initiated.
Type
boolean

DrawImage(img, x, y, frameopt)

This command draws a previously loaded image. This command draws both single image graphics (loaded with the LoadImage command) as well as animated images (loaded with the LoadAnimImage command). You specify where on the screen you wish the image to appear. You can actually 'draw' off the screen as well by using negative values or positive values that are not visible 'on the screen'. Finally, if you are using an animated image (loaded with LoadAnimImage), you can specify which frame of the imagestrip is displayed with the DrawImage command.
Parameters:
Name Type Attributes Description
img object The image handle to draw.
x number The x-coordinate to draw the image at (relative to its handle).
y number The y-coordinate to draw the image at (relative to its handle).
frame number <optional>
The animation frame to draw (1-based).
Source:

DrawText(x, y, value)

Draws text to the screen using the currently active font.
Parameters:
Name Type Description
x number The x-coordinate to draw the text at.
y number The y-coordinate to draw the text at.
value string The text to draw.
Source:

Eof(handle) → {boolean}

Checks if the end of an open file has been reached.
Parameters:
Name Type Description
handle number The file handle.
Source:
Returns:
Type
boolean

FileExists(path) → {boolean}

Checks if a file exists at the given path.
Parameters:
Name Type Description
path string The path to check.
Source:
Returns:
Type
boolean

FilePos(handle) → {number}

Gets the current read/write position in an open file.
Parameters:
Name Type Description
handle number The file handle.
Source:
Returns:
The current position in the file.
Type
number

FileSize(path) → {number}

Gets the size of a file in bytes.
Parameters:
Name Type Description
path string The path to the file.
Source:
Returns:
The size of the file.
Type
number

FileType(path) → {number}

Determines the type of a path.
Parameters:
Name Type Description
path string The path to check.
Source:
Returns:
0 for not found, 1 for a file, 2 for a directory.
Type
number

Float(value) → {number}

Converts a value to a floating-point number.
Parameters:
Name Type Description
value * The value to convert.
Source:
Returns:
Type
number

FontHeight() → {number}

Returns the height of the current font.
Source:
Returns:
The height in pixels.
Type
number

FontWidth() → {number}

Returns the width of a capital 'W' character in the current font.
Source:
Returns:
The width in pixels.
Type
number

FreeSound(handle)

Releases a sound from memory.
Parameters:
Name Type Description
handle number The sound handle to free.
Source:

GrabImage(targetImage, x, y)

Grabs a portion of the current drawing buffer into an existing image.
Parameters:
Name Type Description
targetImage object The destination image handle.
x number The top-left x-coordinate of the grab area.
y number The top-left y-coordinate of the grab area.
Source:

Graphics(width, height, mainLoop)

Initializes the jBB engine and creates the main graphics canvas. This must be the first jBB command called.
Parameters:
Name Type Description
width * canvas width in pixel
height * canvas height in pixel
mainLoop * the main function of your project
Source:

GraphicsHeight() → {number}

This command will tell you the width, in pixels, of the canvas.
Source:
Returns:
The canvas height in pixels.
Type
number

GraphicsWidth() → {number}

This command will tell you the width, in pixels, of the canvas.
Source:
Returns:
The canvas width in pixels.
Type
number

ImageHandle(img) → {Object}

It is occasionally useful to determine the location of an image's image handle. This command returns the X and Y coordinate.
Parameters:
Name Type Description
img object The image handle.
Source:
Returns:
An object containing the x and y coordinates of the handle.
Type
Object

ImageHeight(img) → {number}

Use this command and ImageWidth to return the size of the given image in pixels.
Parameters:
Name Type Description
img object The image handle.
Source:
Returns:
The height in pixels.
Type
number

ImageWidth(img) → {number}

Use this command and ImageHeight to return the size of the given image in pixels.
Parameters:
Name Type Description
img object The image handle.
Source:
Returns:
The width in pixels.
Type
number

ImageXHandle(img) → {number}

It is occasionally useful to determine the location of an image's image handle. This command returns the X coordinate. Use ImageYHandle to get the Y coordinate. Please see MidHandle for more information on the image's image handle.
Parameters:
Name Type Description
img object The image handle.
Source:
Returns:
The x-coordinate of the handle.
Type
number

ImageYHandle(img) → {number}

It is occasionally useful to determine the location of an image's image handle. This command returns the Y coordinate. Use ImageXHandle to get the X coordinate. Please see ;idHandle for more information on the image's image handle.
Parameters:
Name Type Description
img object The image handle.
Source:
Returns:
The y-coordinate of the handle.
Type
number

ImagesCollide(img1, x1, y1, frame1, img2, x2, y2, frame2) → {boolean}

Checks for pixel-perfect collision between two images, correctly handling transformations.
Parameters:
Name Type Description
img1 object The first image handle.
x1 number The x-coordinate of the first image.
y1 number The y-coordinate of the first image.
frame1 number The animation frame of the first image.
img2 object The second image handle.
x2 number The x-coordinate of the second image.
y2 number The y-coordinate of the second image.
frame2 number The animation frame of the second image.
Source:
Returns:
True if any solid pixels overlap, false otherwise.
Type
boolean

ImagesOverlap(img1, x1, y1, img2, x2, y2) → {boolean}

Checks if the bounding boxes of two (potentially transformed) images overlap.
Parameters:
Name Type Description
img1 object The first image handle.
x1 number The x-coordinate of the first image.
y1 number The y-coordinate of the first image.
img2 object The second image handle.
x2 number The x-coordinate of the second image.
y2 number The y-coordinate of the second image.
Source:
Returns:
True if the images' bounding boxes overlap, false otherwise.
Type
boolean

Int(value) → {number}

Converts a value to an integer.
Parameters:
Name Type Description
value * The value to convert.
Source:
Returns:
Type
number

JoyDown(button, padIndexopt) → {boolean}

Checks if a specific gamepad button is currently held down.
Parameters:
Name Type Attributes Default Description
button number The index of the button to check.
padIndex number <optional>
0 The index of the gamepad.
Source:
Returns:
Type
boolean

JoyType(padIndexopt) → {string}

Returns the identifier string for a connected gamepad.
Parameters:
Name Type Attributes Default Description
padIndex number <optional>
0 The index of the gamepad.
Source:
Returns:
Type
string

JoyX(padIndexopt) → {number}

Returns the position of the primary horizontal axis of a gamepad.
Parameters:
Name Type Attributes Default Description
padIndex number <optional>
0 The index of the gamepad.
Source:
Returns:
A value between -1.0 and 1.0.
Type
number

JoyY(padIndexopt) → {number}

Returns the position of the primary vertical axis of a gamepad.
Parameters:
Name Type Attributes Default Description
padIndex number <optional>
0 The index of the gamepad.
Source:
Returns:
A value between -1.0 and 1.0.
Type
number

KeyDown(keyCode) → {boolean}

Checks if a specific key is currently being held down.
Parameters:
Name Type Description
keyCode number The key code to check.
Source:
Returns:
True if the key is down, false otherwise.
Type
boolean

KeyHit(keyCode) → {boolean}

Checks if a specific key was pressed once. This is true for only one frame.
Parameters:
Name Type Description
keyCode number The key code to check.
Source:
Returns:
True if the key was just hit, false otherwise.
Type
boolean

Line(x1, y1, x2, y2)

This command draws a line, in the current drawing color, from one point on the screen to another (from the x,y to x1,y1 location).
Parameters:
Name Type Description
x1 number The starting x-coordinate.
y1 number The starting y-coordinate.
x2 number The ending x-coordinate.
y2 number The ending y-coordinate.
Source:

LoadAnimImage(path, cellWidth, cellHeight, first, count, path, cellWidth, cellHeight, first, count) → {object}

Parameters:
Name Type Description
path *
cellWidth *
cellHeight *
first *
count *
path string The path to the spritesheet file.
cellWidth number The width of a single frame.
cellHeight number The height of a single frame.
first number The index of the first frame in the animation sequence (1-based).
count number The total number of frames in the animation sequence.
Source:
Returns:
  • An image handle.
    Type
    object

LoadBrush(tilesetImage, tileWidth, tileHeight) → {object|null}

Creates a brush object from a tileset image for use with `TileBlock`.
Parameters:
Name Type Description
tilesetImage object The image handle of the tileset.
tileWidth number The width of a single tile.
tileHeight number The height of a single tile.
Source:
Returns:
A brush object.
Type
object | null

LoadFont(name, path, name, path) → {object}

Parameters:
Name Type Description
name *
path *
name string The name to assign to the font-family for CSS.
path string The path to the font file (e.g., .ttf, .woff).
Source:
Returns:
  • A font handle.
    Type
    object

LoadImage(file) → {object}

This command loads an image and assigns it a Jmage object. You will use the DrawImage command to display the graphic later.
Parameters:
Name Type Description
file string The path to the image file.
Source:
Returns:
An image handle.
Type
object

LoadSound(path) → {number}

Loads a sound effect into memory.
Parameters:
Name Type Description
path string The path to the sound file (e.g., .mp3, .wav).
Source:
Returns:
A sound handle.
Type
number

LoadTextFile(path) → {Promise.<(string|null)>}

Asynchronously loads a text file, using a read-through cache. It first checks the virtual file system. If not found or stale, it fetches it from the server.
Parameters:
Name Type Description
path string The path to the text file.
Source:
Returns:
A promise that resolves with the file content or null.
Type
Promise.<(string|null)>

LoopSound(handle, loop)

Sets a sound to loop.
Parameters:
Name Type Description
handle number The sound handle.
loop boolean True to enable looping.
Source:

MidHandle(img)

This command moves the image's handle to the middle of the image.
Parameters:
Name Type Description
img * The image to apply the midhandle to.
Source:

Millisecs() → {number}

Returns the number of milliseconds that have elapsed since the Unix epoch.
Source:
Returns:
Type
number

MouseDown(button) → {boolean}

Checks if a specific mouse button is currently held down.
Parameters:
Name Type Description
button number The button to check (1=left, 2=right, 3=middle).
Source:
Returns:
Type
boolean

MouseHit(button) → {boolean}

Checks if a specific mouse button was just pressed in the current frame.
Parameters:
Name Type Description
button number The button to check (1=left, 2=right, 3=middle).
Source:
Returns:
Type
boolean

MouseX() → {number}

Returns the x-coordinate of the mouse relative to the canvas.
Source:
Returns:
Type
number

MouseY() → {number}

Returns the y-coordinate of the mouse relative to the canvas.
Source:
Returns:
Type
number

MusicVolume(volume)

Sets the volume for the music stream.
Parameters:
Name Type Description
volume number The volume (0.0 to 1.0).
Source:

NextFile(handle) → {string}

Reads the next entry from an open directory handle.
Parameters:
Name Type Description
handle number The directory handle.
Source:
Returns:
The name of the next file or directory.
Type
string

OpenFile(path) → {number}

Opens a file for reading/writing. Creates the file if it doesn't exist.
Parameters:
Name Type Description
path string The path to the file in the virtual file system.
Source:
Returns:
A file handle, or 0 on failure.
Type
number

Oval(x, y, width, height, filled, x, y, width, height, filledopt)

Parameters:
Name Type Attributes Default Description
x *
y *
width *
height *
filled *
x number The x-coordinate of the oval's center.
y number The y-coordinate of the oval's center.
width number The horizontal radius of the oval.
height number The vertical radius of the oval.
filled boolean <optional>
true True to draw a filled oval, false for an outline.
Source:

PauseMusic()

Pauses the currently playing music.
Source:

Pi() → {number}

Returns the value of PI.
Source:
Returns:
Type
number

PlayMusic(path, loopopt)

Streams and plays a music file.
Parameters:
Name Type Attributes Default Description
path string The path to the music file.
loop boolean <optional>
true True to loop the music.
Source:

PlaySound(soundHandle) → {number}

Plays a sound.
Parameters:
Name Type Description
soundHandle number The sound handle to play.
Source:
Returns:
A channel handle for the playing instance of the sound.
Type
number

Plot(x, y)

Used to put a pixel on the screen defined by its x, y location in the current drawing color defined by the Color command
Parameters:
Name Type Description
x number The x-coordinate of the pixel.
y number The y-coordinate of the pixel.
Source:

Rand(min, max) → {number}

Returns a random integer between min and max (inclusive).
Parameters:
Name Type Description
min number The minimum possible value.
max number The maximum possible value.
Source:
Returns:
Type
number

ReadDir(path) → {number}

Opens a directory for reading its contents.
Parameters:
Name Type Description
path string The path to the directory.
Source:
Returns:
A directory handle, or 0 on failure.
Type
number

ReadFile(handle) → {string}

Reads the next line from an open file.
Parameters:
Name Type Description
handle number The file handle.
Source:
Returns:
The content of the line.
Type
string

ReadPixel(x, y) → {Object}

Reads the color data of a single pixel from the main canvas.
Parameters:
Name Type Description
x number The x-coordinate of the pixel.
y number The y-coordinate of the pixel.
Source:
Returns:
An object with the RGBA color components.
Type
Object

Rect(x, y, width, height, filledopt)

This command will draw a rectangle in the current drawing Color starting at the location specified. The last parameter determines if the rectangle is filled or just a 'box'.
Parameters:
Name Type Attributes Default Description
x number The top-left x-coordinate.
y number The top-left y-coordinate.
width number The width of the rectangle.
height number The height of the rectangle.
filled boolean <optional>
true True to draw a filled rectangle, false for an outline.
Source:

RectsOverlap(x1, y1, w1, h1, x2, y2, w2, h2) → {boolean}

Checks if two axis-aligned rectangles overlap.
Parameters:
Name Type Description
x1 number X-coordinate of the first rectangle.
y1 number Y-coordinate of the first rectangle.
w1 number Width of the first rectangle.
h1 number Height of the first rectangle.
x2 number X-coordinate of the second rectangle.
y2 number Y-coordinate of the second rectangle.
w2 number Width of the second rectangle.
h2 number Height of the second rectangle.
Source:
Returns:
True if the rectangles overlap, false otherwise.
Type
boolean

ResumeMusic()

Resumes paused music.
Source:

RotateImage(img, value)

rotate an image a specified number of degrees
Parameters:
Name Type Description
img * a Jmage object
value * floating number from 0 to 360 degrees
Source:

ScaleImage(img, x, y)

Use this command to rescale an image to a new size using a floating point percentage (1.0 = 100%, 2.0 = 200%, etc). Using a negative value perform image flipping. You must've previously loaded the image with LoadImage or LoadAnimImage.
Parameters:
Name Type Description
img object The image handle to scale.
x number The horizontal scale factor (e.g., 1.0 for 100%).
y number The vertical scale factor.
Source:

SeekFile(handle, pos)

Sets the read/write position for an open file.
Parameters:
Name Type Description
handle number The file handle.
pos number The new position to seek to.
Source:

SetBlendMode(mode)

Sets the composition mode for all subsequent drawing operations.
Parameters:
Name Type Description
mode string The blend mode to apply (e.g., "add", "multiply", "screen").
Source:

SetBuffer(buffer)

Sets the current drawing target to an image buffer or the main screen.
Parameters:
Name Type Description
buffer object | null The image created with `CreateImage` to draw on, or the value from `BackBuffer()` to draw to the screen.
Source:

SetFont(fnt, size, boldopt, italicopt)

Sets the active font for subsequent text drawing operations.
Parameters:
Name Type Attributes Default Description
fnt object The font handle.
size number The font size in pixels.
bold boolean <optional>
false True to make the font bold.
italic boolean <optional>
false True to make the font italic.
Source:

SoundPan(handle, pan)

Sets the default stereo panning for a sound.
Parameters:
Name Type Description
handle number The sound handle.
pan number The pan value (-1.0 is left, 0.0 is center, 1.0 is right).
Source:

SoundPitch(handle, pitch)

Sets the default pitch for a sound.
Parameters:
Name Type Description
handle number The sound handle.
pitch number The pitch multiplier (1.0 is normal).
Source:

SoundVolume(handle, volume)

Sets the default volume for a sound.
Parameters:
Name Type Description
handle number The sound handle.
volume number The volume (0.0 to 1.0).
Source:

Start()

Starts the game engine after all assets have been queued for loading. This function must be called at the end of your main script.
Source:

StopChannel(channelHandle)

Stops a playing sound on a specific channel.
Parameters:
Name Type Description
channelHandle number The channel handle returned by `PlaySound`.
Source:

StopMusic()

Stops the currently playing music and rewinds it to the beginning.
Source:

StringHeight(value) → {number}

Measures the height of a string using the currently active font.
Parameters:
Name Type Description
value string The string to measure.
Source:
Returns:
The height in pixels.
Type
number

StringWidth(value) → {number}

Measures the width of a string using the currently active font.
Parameters:
Name Type Description
value string The string to measure.
Source:
Returns:
The width in pixels.
Type
number

TFormFilter(value)

This command will enable or disable bi-linear filtering on images
Parameters:
Name Type Description
value * false to turn off filtering; true to turn it on
Source:

TileBlock(brush, mapData, xopt, yopt)

Draws a map of tiles using a specified brush.
Parameters:
Name Type Attributes Default Description
brush object The brush object created by `LoadBrush`.
mapData Array.<Array.<number>> A 2D array of 1-based tile IDs.
x number <optional>
0 The top-left screen X coordinate to start drawing the map.
y number <optional>
0 The top-left screen Y coordinate to start drawing the map.
Source:

WriteFile(handle, text)

Appends a line of text to an open file.
Parameters:
Name Type Description
handle number The file handle.
text string The text to write.
Source: