Examples

This is an automatically generated documentation page. For specific examples, check here!

GameAudio

Function:

GameAudio.init(collection, containingFolder)

Starts the audio system, using an array of audio names 'collection' and a path 'containingFolder' in which the sounds can be found. Do not include file extentions in sound names!

Function:

GameAudio.play(name)

plays a sound with the name 'name'.

Engine

Function:

Engine.loadScripts(scripts, callback)

Include an array 'scripts' from an external source. When finished, start the function 'callback'.

Game

Property:

Game.activeObjects

array containing all existing objects.

Property:

Game.stepsSinceStart

Total amount of update steps since the start of the game.

Function:

Game.initialize(windowX, windowY, windowWidth, windowHeight, fps, loadedCallback)

Starts the game, and creates a window at ('windowX', 'windowY'), using 'windowWidth' and 'windowHeight' as sizes for the game window in pixels. 'fps' controls the game's frames-per-second'. As soon as the game is loaded up, it'll call the function 'loadedCallback', so you can properly start the game.

Function:

Game.setUpdateFunction(callback)

Assigns a function 'callback' to be called every frame of the game. You can use this to run global code for your game.

Function:

Game.clearScene()

destroys every object in the scene.

GameInput

Function:

GameInput.IsPressed(keyCode)

Returns true if the key with given code 'keyCode' was pressed this frame. Only returns true the frame the key is pressed once until the key is released and pressed again.

Function:

GameInput.isHeld(keyCode)

returns true if the key with given code 'keyCode' is currently pressed.

GameObject

Function:

GameObject.create(template, x, y)

Creates a new Game Object using the object template 'template' at the position ('x', 'y')

Property:

object.active

Object is visible and executes it's code when this parameter is true. Set to false to hide and disable the object temporarily.

Property:

object.name

The name of the current object. Defaults to "Object".

Property:

object.image

The path to the image this object should use. When not set, an object will appear as a square.

Property:

object.text

Text to be displayed in an object. Warning: May currently not work properly.

Property:

object.color

Color of the object. Fills in entire hitbox, and as such acts more as a highlighter. Accepts css colors such as "#FF0000" or "red". Set to "clear" for transparency.

Property:

object.ignoreCollisions

Ignores this object when checking for collisions. Useful for background objects.

Property:

object.transform.position

A vector() containing the object's position. (measured from object center)

Property:

object.transform.velocity

A vector() containing the object's speed. (measured from object center)

Property:

object.transform.rotation

the object's rotation in degrees. Default is zero.

Property:

object.transform.width

the width of the object, defaults to 32.

Property:

object.transform.height

the height of the object, defaults to 32.

Function:

object.transform.pointTowards(point)

Adjust object.transform.rotation to point at vector2() 'point'.

Function:

object.transform.left()

A single pixel left of the object, accounting for rotation.

Function:

object.transform.right()

A single pixel right of the object, accounting for rotation.

Function:

object.transform.forward()

A single pixel forwards of the object, accounting for rotation.

Function:

object.transform.back()

A single pixel backwards of the object, accounting for rotation.

Function:

object.start()

Called on object's creation. Override this on your own object templates!

Function:

object.start()

Called on each frame start! (Before collision checks of this frame) Override this on your own object templates!

Function:

object.onCollision(other)

Called on object collision. Parameter 'other' is a reference to the object you're colliding with! Override this on your own object templates!

Function:

object.destroy()

Destroys the current object at the end of the current update step.

Function:

object.onDestroy()

Called on object's destruction. Override this on your own object templates!

vector()

Property:

vector.x

the X axis of the vector.

Property:

vector.y

the Y axis of the vector.

Function:

vector.length()

returns the length of the vector.

Function:

vector.toAngle()

Get the angle towards the vector's direction in degrees.

Function:

vector.normalize()

returns a normalized copy of the vector. Original vector is not modified.

Function:

vector.lerpTo(otherVector, t)

Returns a new vector between this vector and 'otherVector' at point 't'. 0t = original vector, 1t = 'otherVector', 0.5t is halfway in between.

Function:

vector.distanceTo(otherVector)

returns the distance to another vector.

Function:

vector.add(otherVector)

adds the two vectors together, and returns as a copy. Original vector is not modified.

Function:

vector.subtract(otherVector)

subtracts the second vector from this vector, and returns as a copy. Original vector is not modified.

Function:

vector.multiply(otherVector)

multiplies the first vector X by the second vector's X, and the first's Y by the second's Y, and returns as a copy. Original vector is not modified.

Function:

vector.divide(otherVector)

divides the first vector by the second, and returns as a copy. Original vector is not modified.

Function:

vector.stretch(length)

Multiplies the vector by the given numeric value, and returns as a copy. Original vector is not modified.

Function:

vector.getCopy()

returns a copy of this vector.

GameWindow

Property:

GameWindow.width
The game window's width. Cannot be changed.

Property:

GameWindow.height
The game window's height. Cannot be changed.