gma.manager

Provides basic setup functionality

Package gma/manager

Properties

width

Holds the width of the canvas

Type Number
Default 800

height

Holds the height of the canvas

Type Number
Default 600

containerID

Id for the gamma div

Type String
Default “gamma”

container

The gamma div

Type Element
Default $(“#gamma”)

canvas

Holds the canvas

Type DOM Element

sceneHelper

Helper object connecting manager to rendering library

Type gma.sceneHelper

resources

List of resources to give the renderer

Type [String]

levelParser

The manager’s levelParser object

Type gma.levelParser

levels

Holds the level specs

Type List
Default []

levelIndex

Holds the level index. (a level must be loaded first for it to be accurate)

Type Number
Default 0

hud

Holds the hud

Type gma.hud

showLoading

Specifies whether it should display a loading message

Type Boolean
Default true

character

Holds a character object
This is optional
Type gma.character
Default undefined

time

Holds the last time scene was rendered

Type Number

counter

Holds an accumulation of time to be used for fps calculation

Type Number
Default 0

fps

Holds the frames per second

Type Number
Default 0

twitchCount

Number of times the scene has twitched since fps last calculated

Type Number
Default 0

Methods

getFPS ( ) -> Number
Get the current FPS
background ( ) -> Array
Returns a list of all background
entities ( ) -> Array
Returns a list of all entities in the current level
determineObject (type, opts) -> Gamma Object
Returns a gamma object given the type given
If type is a string, then we look on gma to see if it exists
Otherwise it is used as is
And any options supplied in the opts object is applied to this object
Parameters
type Gamma Object or string Name of a gamma object or just a gamma object
opts Gamma Object or string Name of a gamma object or just a gamma object
prepareEntity (focus, template, opts) -> Gamma Object
Attaches renderHelper and renderTemplate to the gamma object given
Also applies any extra options to this Gamma object
Parameters
focus Gamma Object Gamma object
template renderTemplate A renderTemplate object to be given to the gamma object
opts {} Options to be applied to the gamma object
addCustomDefinitions (opts)
Gives an object othe levelParser to process, without storing the result anywhere
Useful for giving the levelParser type and template specifications
Which end up stored on the levelParser
Parameters
opts Object Options that are given to the levelParser
storeLevels (levels, replaceAll)

Stores level specifications on the manager

Parameters
levels Array A list of level objets to store
replaceAll Boolean Flag specifying whether to replace all current levels
loadLevel (level, spawnId)
Will load the specified level into the manager
Or the first level in self.levels if no level is specified
Or complain if manager has no stored levels
It will also remove any current levels in the manager
And set the position of the character according to the spawn location specified
Parameters
level Number The index of the level to load
spawnId String Id of the spawn location for character
clearLevel ( )
Clears the current level from the scenehelper
init (level, spawn)
Called when we want the game to start
It creates a Scene and then starts the twitch
It will also call loadLevel if no level is currently loaded
Or if a level has been specified
Parameters
level Number The index of the level to load
spawn String Alternate spawn point to use
twitch (self)
The game loop function
Responsible for :
  • Calling animate
  • Calling render
  • Calculating fps
  • Removing entities that are dead
  • Calling itself again to continue the loop
Parameters
self gma.manager
animate (tick)

Calls the animate function on objects inside the map

Parameters
tick Integer Number representing the time since the last twitch
removeDead (entities, cemetry)

Removes any dead entities from the map

Parameters
entities List List of entities to look through
cemetry List List to add dead entities to if they have the reincarnate tag
checkCharacter ( )
Determines if the character is dead and does something about it if it is
respawn (spawnId)

Puts character back to the beginning

Parameters
spawnId String String specifying where to respawn the character. This defaults to “main”

Table Of Contents

Fork me on GitHub