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(deltaTime)' 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.

Function:

Constructor: new image(urlToImage, subImages = 1, subImagesPerRow = 1)

Function:

image.draw(sourceX, sourceY, sourceWidth, destX, destY, destWidth, destHeight, rotation, alpha)

Draw the image on screen.

Image. Create using: new image(urlToImage)

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

An image object.

Property:

object.ignoreCollisions

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

Property:

object.renderer

Used for methods and variables related to drawing the object on the screen.

Property:

object.renderer.image

The image to draw.

Property:

object.renderer.subImage

The current subimage to draw using the default draw method

Property:

object.renderer.alpha

Image transparency (0-1) default: 1

Property:

object.renderer.visible

Value indicating if the object should be drawn (true/false)

Function:

image.draw(x, y, w, h, rotation, alpha = 1)

Draw an image at (x,y), size (w,h), at an angle in degrees.

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.draw()

Called on each draw step. If not overridden, default draw is used!

Function:

object.update(deltaTime)

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.

Property:

GameWindow.backgroundColor
Background color. Contains an r, g and b component (0-255).

Property:

GameWindow.canvas

The game's canvas element

Property:

GameWindow.canvasContext

The game's canvasContext. Use this for drawing.