MGLUE
Game Actor ActorGroup Drawing Sound Vector
Game

constructor

currentState: string = GameState.title

highScore: number = -1

lastScore: number = -1

leaderboardEnabled: boolean = false

leaderboardText: TextActor = new TextActor("")
actor used to display the leaderboard

score: number = 0

display: DisplayInterface = undefined

gameOver

ticks
number of frames that has elapsed since the game started

INTERVAL

enableLeaderboard(leaderboardUrl: string)

endGame()

onBeginGame()

onEndGame()

update()

updateLeaderboard()

updateTitle()

runOnReady(fn: Function)
Helper function to run the game after the window loads, or if the window is ready, immediately

Actor

You are going to make your game out of a pile of these. Contains very basic movement, updating, and drawing. Also where you handle overlap detection and removing things from groups.

class Enemy extends Actor
{
     begin()
     {

         // this actor will move down the screen 1/100 of the distance per frame
         // velocity is automatically integrated after the update call
         this.velocity.set(0, 0.01);

         // setup the drawing that will be used for this actor
         // drawn to the screen after every update
         this.drawing
             .setColor(Color.red)
             .addRect(0.01);
     }
     update()
     {
         // check if this object is overlapping an actor of type Player
         this.checkOverlap(Player, (p:player)=>{
             // destroy the player that is overlapped
             p.destroy();
         });
     }
}

The drawing property is also what is used for overlap checks between actors, so if you want differently sized hitboxes, make sure to add additional drawings to your actor.

constructor

age: number = 0
Number of frames the actor has been alive for.

drawing: Drawing = new Drawing()
Default drawing for the actor. This drawing is automatically added to the game during update.

group: ActorGroup = undefined
group this actor belongs to

isDestroying: boolean = false

position: Vector = new Vector(0,0)
Current position of the actor. Used for both drawing and overlap checks.

rotation: number = 0
Rotation of the actor in degrees.

scale: Vector = new Vector(1,1)

velocity: Vector = new Vector(0,0)
How fast the actor is moving. This value is added to the actors position every update loop.

totalCount: number = 0
Number of actors in the game.

begin(args)

checkOverlap(targetClass: any, [handler: Function])
Collision handling method.

Returns true if an overlap is found. Uses the .drawing property on the actor to check for overlaps between quads. Call during the Actors update function.

update()
{
     this.checkOverlap(Enemy, (e : Enemy)=>{
          console.log("overlapping enemy!");
          e.kill();
     });
}

destroy()
Mark this actor to be removed from the game at the end of the current update loop.

initialize()

lateUpdate()

setDisplayPriority(displayPriority: number)

setPosition(p: Vector)

setVelocity(velocity: Vector)

update()
Override this function, it will be called every frame while the actor is in the game.

clear()

getGroup(targetClass: any)

scroll(targetClass, offset: Vector)
Adds a vector value to all actors within a class, or a group of classes. Can be used to simulate camera type effects.

sortGroups()

update()

ActorGroup

Collection of Actors. Each new actor subclass generates a group, though you can create further ones if necessary. Actors are automatically added to their class group on creation. The main actor groups are tracked by `Game` to handle updating, so don't mess with them too much.

Most accessing of this class happens through the actor class.

class Player extents Actor {}
let p = new Player();
if(Actor.getGroup(Player).members[0] == p)
{
     console.log("you found the player!");
}

constructor

displayPriority: number = 1

members: undefined = undefined

name: string = undefined

clear()

update()

Drawing

hasCollision: boolean = true

position: Vector = new Vector(0,0)

rotation: number = 0

scale: Vector = new Vector(1,1)

addArc(angle: number, count: number)

addRect(width: number, height: number, offsetX: number, offsetY: number)

addSegementedRect(width: number, height: number, offsetX: number, offsetY: number, angle: number)

draw()

isOverlapping(other: Drawing)

mirrorX()

mirrorY()

setColor(color: Color)

setPosition(v: Vector)

setRotation(r: number)

updateState()

Sound

constructor

play()
schedules the sound to play at the next quantized time

playNow()

playPattern()
Plays the sound as a looping pattern. Will throw an error if the sound doesn't have a pattern defined.

remove()
removes a playing sound from the scheduled sounds.

setFromParams(params: any)

setPattern(pattern: any, patternInterval: number)

generateDrumParams(seed: number)

generateDrumPattern(seed: number)

generateParams(seed: any, params: any, mixRatio: number)

initialize()
call to set up all static properties

setSeed(seed: number)
Change the seed that is used by the Sound internal Random instance.

update()
call once per frame to update all playing loops, and play sounds that are linked to quantization.

Vector

constructor

x: number = undefined

y: number = undefined

add(other: Vector)

addDirection(degrees: number, amount: number)

copy()
Returns a copy of this vector

directionTo(other: Vector)

divide(scalar: number)

length()

multiply(scalar: number)

normalize()

onScreen()

rotate(angleDegrees: number)

rotation()

set(x: number, y: number)

subtract(other: Vector)

distance(a: Vector, b: Vector)