Library

Overview

This is the full documentation for every class used in the Budgie game engine. Hidden fields are not shown here, as they should not be accessed directly or it may cause unintended behavior. Documentation is split up by classes, where each class has multiple fields and methods.

Here are shortcuts to each of the classes:

Budgie Sprite AssetsManager StorageManager KeysManager

class Budgie

This class represents that entire game engine. It is automatically instantiated, so you should never have to call the constructor. You can access this class with the budgie variable.

field storage

This is an instance of StorageManager and allows you to save or load save data for your game

field assets

This is an instance of AssetsManager and allows you to access your loaded game assets

field keys

This is an instance of KeysManager and helps with key event processing

field mouse

This is an invisible Sprite that represents the player's mouse pointer

function onstart()

This function gets called by Budgie when all the assets are done loading. It is a hook that you'll have to implement yourself. You can do this like so:

function onclick()

This function gets called whenever the player clicks with the mouse. It is a hook that you'll have to implement yourself. You can do this like so:

function onkeyevent(e)

This function gets called whenever the player presses, holds or releases a key on the keyboard. It is a hook that you'll have to implement yourself. You can do this like so:


It also takes the following parameters:

function onframe(delta)

This function gets called once every frame. It is a hook that you'll have to implement yourself. You can do this like so:


It also takes the following parameters:

function error(msg)

This function prints an error message to the browser console and halts the game loop. It is called at several points in the engine to catch potential errors made by game developers. You can also use it for debugging. This function takes the following parameters:

function getWidth()

This function returns the intended canvas width for your game

function getHeight()

This function returns the intended canvas height for your game

function addSprite(child)

This function adds a new sprite object onto the view. It takes in the following parameters:

function removeSprite(child)

This function adds a new sprite object onto the view. It takes in the following parameters:


class Sprite

This class represents a basic game object within the engine. You can instantiate a new Sprite by calling new Sprite().

constructor Sprite()

Initializes a new Sprite instance

field children

A list of this sprite's child sprites

field parent

This sprite's parent sprite. Will be null if this sprite has no parent.

function overlaps(sprite)

Returns true if this sprite overlaps with the sprite given as an argument. Overlap is calculated by bounding rectangles. This function takes the following arguments:

function addBounds(x,y,w,h)

Extends the area of this sprite's bounding rectangle. This function takes the following arguments:

function getBounds(sprite)

Returns this sprite's bounding rectangle in absolute coordinates. Returns an object with x, y, width, and height fields.

function render()

This hook is called every time the sprite is supposed to redraw itself onto the canvas. You can implement it like so:

function setColor(r,g,b)

Sets the color to be used for draw functions. Takes the following arguments:

function setDrawStyle(fill)

Sets the draw style, whether that be fill or stroke. Takes the following arguments:

function setLineWidth(lw)

Sets the line width of your draw functions. Takes the following arguments:

function drawImage(img,x,y,sx,sy)

Renders an image as part of this sprite. Takes the following arguments:

function drawRect(x,y,w,h)

Renders a rectangle as part of this sprite. Takes the following arguments:

function drawOval(x,y,w,h)

Renders an oval as part of this sprite. Takes the following arguments:

function setFont(font,size)

Sets the font to be used when rendering text. Uses the following arguments:

function drawText(txt,x,y,w)

Renders text on the canvas as part of this sprite. This function takes the following arguments:

function update(delta)

This function is called every frame. You can implement it like so:


This function takes the following arguments:

function onclick()

This function is called whenever this sprite is clicked on. You can implement it like so:

function addChild(child)

Adds a child sprite to this sprite. Takes the following arguments:

function removeChild(child)

Removes a child sprite from this sprite. Takes the following arguments:

function moveToBack()

Tells this sprite's parent to draw this sprite behind its siblings

function moveToFront()

Tells this sprite's parent to draw this sprite in front of its siblings

function placeBehind(sprite)

Tells this sprite's parent to draw this sprite behind sprite. Takes the following arguments:

function placeInFront(sprite)

Tells this sprite's parent to draw this sprite in front of sprite. Takes the following arguments:

function getOffset()

Returns an object with x and y fields representing this sprite's offset from its parent

function addOffset(x,y)

Increments this sprite's offset from its parent. Takes the following arguments:

function setOffset(x,y)

Sets this sprite's offset from its parent. Takes the following arguments:

function drawLine(x1,y1,x2,y2)

Draws a line on this sprite. Takes the following arguments:

function drawShape(...)

Draws a polygon on this sprite. This function take two arguments (x and y) for every point in your desired shape. You must provide at least three points (six arguments) or this function will throw an error. Takes the following arguments:

function getContext()

Returns the HTML5 2D canvas context object associated with this sprite. You can extend Budgie's capabilities by accessing the underlying HTML5 context directly.


class AssetsManager

This class is used by the engine to load and control access to assets. You can access it via budgie.assets.

function getProgress()

This function returns a value between 0 and 1 representing the percentage of assets that have been loaded. You can use this function to implement loading screens, for example.

function getAsset(path)

This function gives you a handle to any loaded asset you'd like. It takes the following parameters:


class StorageManager

This class is used by the engine to load and save game data. It allow you to pull saved state from the browser, edit it, and later write it back for storage. You can access it via budgie.storage.

function get(k)

This function gets one piece of data from saved state. It takes the following parameters:

function put(k,v)

This function puts one piece of data into saved state. It takes the following parameters:

function remove(k)

This function removes one piece of data from saved state. It takes the following parameters:

function delete()

This function clears your saved state from the browser storage

function save()

This function writes your saved state to the browser storage

function load()

This function reads your saved state from the browser storage


class KeysManager

This class is used by the engine to handle key events. You can access it via budgie.keys.

const ACTION_DOWN

Represents the action where a key was pressed

const ACTION_HOLD

Represents the action where a key is being held down

const ACTION_UP

Represents the action where a key was released

const KEY_BACKSPACE

Represents the backspace key

const KEY_TAB

Represents the tab key

const KEY_ENTER

Represents the enter key

const KEY_SHIFT

Represents the shift key

const KEY_CTRL

Represents the ctrl key

const KEY_ALT

Represents the alt key

const KEY_CAPS_LOCK

Represents the caps_lock key

const KEY_ESC

Represents the esc key

const KEY_SPACE

Represents the space key

const KEY_PAGE_UP

Represents the page_up key

const KEY_PAGE_DOWN

Represents the page_down key

const KEY_END

Represents the end key

const KEY_HOME

Represents the home key

const KEY_LEFT

Represents the left key

const KEY_UP

Represents the up key

const KEY_RIGHT

Represents the right key

const KEY_DOWN

Represents the down key

const KEY_INSERT

Represents the insert key

const KEY_DELETE

Represents the delete key

const KEY_0

Represents the 0 key

const KEY_1

Represents the 1 key

const KEY_2

Represents the 2 key

const KEY_3

Represents the 3 key

const KEY_4

Represents the 4 key

const KEY_5

Represents the 5 key

const KEY_6

Represents the 6 key

const KEY_7

Represents the 7 key

const KEY_8

Represents the 8 key

const KEY_9

Represents the 9 key

const KEY_A

Represents the a key

const KEY_B

Represents the b key

const KEY_C

Represents the c key

const KEY_D

Represents the d key

const KEY_E

Represents the e key

const KEY_F

Represents the f key

const KEY_G

Represents the g key

const KEY_H

Represents the h key

const KEY_I

Represents the i key

const KEY_J

Represents the j key

const KEY_K

Represents the k key

const KEY_L

Represents the l key

const KEY_M

Represents the m key

const KEY_N

Represents the n key

const KEY_O

Represents the o key

const KEY_P

Represents the p key

const KEY_Q

Represents the q key

const KEY_R

Represents the r key

const KEY_S

Represents the s key

const KEY_T

Represents the t key

const KEY_U

Represents the u key

const KEY_V

Represents the v key

const KEY_W

Represents the w key

const KEY_X

Represents the x key

const KEY_Y

Represents the y key

const KEY_Z

Represents the z key

const KEY_NUM_0

Represents the num_0 key

const KEY_NUM_1

Represents the num_1 key

const KEY_NUM_2

Represents the num_2 key

const KEY_NUM_3

Represents the num_3 key

const KEY_NUM_4

Represents the num_4 key

const KEY_NUM_5

Represents the num_5 key

const KEY_NUM_6

Represents the num_6 key

const KEY_NUM_7

Represents the num_7 key

const KEY_NUM_8

Represents the num_8 key

const KEY_NUM_9

Represents the num_9 key

const KEY_MULT

Represents the mult key

const KEY_ADD

Represents the add key

const KEY_SUB

Represents the sub key

const KEY_DECIMAL

Represents the decimal key

const KEY_DIV

Represents the div key

const KEY_F1

Represents the f1 key

const KEY_F2

Represents the f2 key

const KEY_F3

Represents the f3 key

const KEY_F4

Represents the f4 key

const KEY_F5

Represents the f5 key

const KEY_F6

Represents the f6 key

const KEY_F7

Represents the f7 key

const KEY_F8

Represents the f8 key

const KEY_F9

Represents the f9 key

const KEY_F10

Represents the f10 key

const KEY_F11

Represents the f11 key

const KEY_F12

Represents the f12 key

const KEY_NUM_LOCK

Represents the num_lock key

const KEY_SCROLL_LOCK

Represents the scroll_lock key

const KEY_SEMICOLON

Represents the semicolon key

const KEY_EQUAL

Represents the equal key

const KEY_COMMA

Represents the comma key

const KEY_DASH

Represents the dash key

const KEY_PERIOD

Represents the period key

const KEY_FORWARD_SLASH

Represents the forward_slash key

const KEY_OPEN_BRACKET

Represents the open_bracket key

const KEY_BACK_SLASH

Represents the back_slash key

const KEY_CLOSE_BRACKET

Represents the close_bracket key

const KEY_SINGLE_QUOTE

Represents the single_quote key