Members
(constant) _soundCache :Record.<string, HTMLAudioElement>
Type:
- Record.<string, HTMLAudioElement>
- Source:
backgroundImg :HTMLImageElement|null
The background image, if set
.The background image, if set
Type:
- HTMLImageElement | null
- Source:
canvaX :number
Fixed canvas width in pixels
.Fixed canvas width in pixels
Type:
- number
- Source:
canvaY :number
Fixed canvas height in pixels
.Fixed canvas height in pixels
Type:
- number
- Source:
(constant) canvasEl :HTMLCanvasElement
The main canvas element
.The main canvas element
Type:
- HTMLCanvasElement
- Source:
(constant) ctx :CanvasRenderingContext2D
The 2D rendering context for the canvas
.The 2D rendering context for the canvas
Type:
- CanvasRenderingContext2D
- Source:
(constant) cursor :Object
The cursor object tracks mouse position and button states.
The cursor object tracks mouse position and button states.
Type:
- Object
- Source:
debug :boolean
Enables debug mode to show mouse position and hover info
.Enables debug mode to show mouse position and hover info
Type:
- boolean
- Source:
(constant) drawables :Array.<Drawable>
Array of drawable objects (sprites and text)
.Array of drawable objects (sprites and text)
Type:
- Array.<Drawable>
- Source:
(constant) hoverInfoEl :HTMLElement
Element displaying hover information
.Element displaying hover information
Type:
- HTMLElement
- Source:
(constant) keys :Object.<string, boolean>
Tracks current keyboard states
.Tracks current keyboard states
Type:
- Object.<string, boolean>
- Source:
(constant) mousePosEl :HTMLElement
Element displaying mouse position
.Element displaying mouse position
Type:
- HTMLElement
- Source:
(constant) prevKeys :Object.<string, boolean>
Tracks previous keyboard states
.Tracks previous keyboard states
Type:
- Object.<string, boolean>
- Source:
Methods
LibraryLoopMGB()
The main game loop, handling updates and rendering.
The main game loop, handling updates and rendering.
- Source:
_copyProps(src, dst, props)
Copies a whitelist of properties from one object to another.
Copies a whitelist of properties from one object to another.
Parameters:
| Name | Type | Description |
|---|---|---|
src |
T | Source object. |
dst |
T | Destination object. |
props |
Array.<string> | Property names to copy. |
- Source:
_removeFromArray(arr, item)
Removes an item from an array without leaving holes.
Removes an item from an array without leaving holes.
Parameters:
| Name | Type | Description |
|---|---|---|
arr |
Array.<*> | |
item |
* |
- Source:
autoGenerateHitbox(sprite, alphaThresholdopt)
Generates and assigns a hitbox for a sprite’s current costume.
Generates and assigns a hitbox for a sprite’s current costume.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
sprite |
Sprite | The sprite to generate a hitbox for. |
||
alphaThreshold |
number |
<optional> |
10 | Alpha value to detect edges. |
- Source:
convexHull(points) → {Array.<{x: number, y: number}>}
Computes the convex hull of a set of points using Graham Scan.
Computes the convex hull of a set of points using Graham Scan.
Parameters:
| Name | Type | Description |
|---|---|---|
points |
Array.<{x: number, y: number}> | The input points. |
- Source:
Returns:
The convex hull vertices.
- Type
- Array.<{x: number, y: number}>
createSprite(xopt, yopt, coloropt, …imageSrcs) → {Sprite}
Creates a new sprite and adds it to drawables.
Creates a new sprite and adds it to drawables.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
x |
number |
<optional> |
0 | The starting x-coordinate. |
y |
number |
<optional> |
0 | The starting y-coordinate. |
color |
string |
<optional> |
'white' | The sprite color. |
imageSrcs |
string |
<repeatable> |
Optional image sources for costumes. |
- Source:
Returns:
The created sprite.
- Type
- Sprite
createText(x, y, color, text, fontopt, doCenteropt) → {Text}
Creates a new text object and adds it to drawables.
Creates a new text object and adds it to drawables.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
x |
number | The x-coordinate. |
||
y |
number | The y-coordinate. |
||
color |
string | The text color. |
||
text |
string | The text content. |
||
font |
string |
<optional> |
"20px monospace" | The font style. |
doCenter |
boolean |
<optional> |
false | Whether to center the text horizontally. |
- Source:
Returns:
The created text object.
- Type
- Text
createTypeBox(x, y, wopt, hopt) → {RealTypeBox}
Factory that mimics createSprite / createText.
Factory that mimics createSprite / createText.
const tb = createTypeBox(60, 500, 400, 40);
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
x |
number | Left-top x (canvas coords). |
||
y |
number | Left-top y (canvas coords). |
||
w |
number |
<optional> |
400 | Width (px). |
h |
number |
<optional> |
40 | Height (px). |
- Source:
Returns:
The created textbox instance.
- Type
- RealTypeBox
cross(o, a, b) → {number}
Computes the cross product for three points.
Computes the cross product for three points.
Parameters:
| Name | Type | Description |
|---|---|---|
o |
Object | Origin point. |
a |
Object | First point. |
b |
Object | Second point. |
- Source:
Returns:
The cross product value.
- Type
- number
forever(callback) → {function}
Repeats a callback every animation frame, like Scratch's "forever" loop.
Repeats a callback every animation frame, like Scratch's "forever" loop.
Parameters:
| Name | Type | Description |
|---|---|---|
callback |
function | The function to call each frame. |
- Source:
Returns:
A function that cancels the loop when called.
- Type
- function
generateHitboxFromImage(image, alphaThresholdopt) → {Array.<{x: number, y: number}>}
Generates a hitbox polygon from an image’s edge pixels.
Generates a hitbox polygon from an image’s edge pixels.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
image |
HTMLImageElement | The source image. |
||
alphaThreshold |
number |
<optional> |
10 | Alpha value to detect edges. |
- Source:
Returns:
The hitbox polygon vertices.
- Type
- Array.<{x: number, y: number}>
hide(object)
Hides a drawable object.
Hides a drawable object.
Parameters:
| Name | Type | Description |
|---|---|---|
object |
Drawable | The object to hide. |
- Source:
playSound(url, volumeopt, loopopt) → {HTMLAudioElement}
Plays a sound file.
Plays a sound file.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
url |
string | The path or URL of the sound file. |
||
volume |
number |
<optional> |
1 | Volume level (0.0 to 1.0). |
loop |
boolean |
<optional> |
false | Whether to loop the sound. |
- Source:
Returns:
The Audio object, useful for stopping playback.
- Type
- HTMLAudioElement
polygonsIntersect(poly1, poly2) → {boolean}
Checks if two polygons intersect using SAT.
Checks if two polygons intersect using SAT.
Parameters:
| Name | Type | Description |
|---|---|---|
poly1 |
Array.<{x: number, y: number}> | First polygon vertices. |
poly2 |
Array.<{x: number, y: number}> | Second polygon vertices. |
- Source:
Returns:
True if the polygons intersect.
- Type
- boolean
(async) repeat(times, callback) → {Promise.<void>}
Repeats a callback a set number of times, with one frame between each call.
Repeats a callback a set number of times, with one frame between each call.
Parameters:
| Name | Type | Description |
|---|---|---|
times |
number | Number of times to repeat. |
callback |
function | The function to run each time. |
- Source:
Returns:
A promise that resolves after all repeats are done.
- Type
- Promise.<void>
setBackground(srcopt)
Sets the background image or clears it.
Sets the background image or clears it.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
src |
string |
<optional> |
The path to the image source. If falsy, clears the background. |
- Source:
show(object)
Shows a drawable object.
Shows a drawable object.
Parameters:
| Name | Type | Description |
|---|---|---|
object |
Drawable | The object to show. |
- Source:
wait(ms) → {*}
Makes your code run after this.
Makes your code run after this. Only work for async function.
Parameters:
| Name | Type | Description |
|---|---|---|
ms |
* | The ms you want to wait |
- Source:
Returns:
- Type
- *