API Docs for: 0.2.0
Show:

Q.GameState Class

Extends Q.GameObject
Defined in: lib/quintus.js:1144
Module: Quintus

Generic Game State object that can be used to track of the current state of the Game, for example when the player starts a new game you might want to keep track of their score and remaining lives:

Q.reset({ score: 0, lives: 2 });

Then in your game might want to add to the score:

 Q.state.inc("score",50);

In your hud, you can listen for change events on the state to update your display:

 Q.state.on("change.score",function() { .. update the score display .. });

Methods

add

(
  • components
)
Object

Adds one or more components to an object. Accepts either a comma separated string or an array of strings that map to component names.

Instantiates a new component object of the correct type (if the component exists) and then triggers an addComponent event.

For example:

this.add("2d, aiBounce")

Returns the object to allow chaining.

Parameters:

  • components String
    • comma separated list of components to add

Returns:

Object:

returns this for chaining purposes

debind

()

Inherited from Q.Evented: lib/quintus.js:907

debind is called to remove any listeners an object had on other objects. The most common case is when an object is destroyed you'll want all the event listeners to be removed for you.

dec

(
  • property
  • amount
)

Defined in lib/quintus.js:1222

Increment an individual property by amount, uses set internally

Parameters:

  • property String
  • amount Integer
    • amount to decrement by

del

(
  • components
)
Object

Inherited from Q.GameObject but overwritten in lib/quintus.js:1081

Removes one or more components from an object. Accepts the same style of parameters as add. Triggers a delComponent event and and calls destroy on the component.

Returns the element to allow chaining.

Parameters:

  • components String
    • comma separated list of components to remove

Returns:

Object:

returns this for chaining purposes

extend

(
  • className
  • properties
  • [classMethods]
)

Inherited from Q.Class: lib/quintus.js:693

Create a new Class that inherits from this class

Parameters:

  • className String
  • properties Object
    • hash of properties (init will be the constructor)
  • [classMethods] Object optional
    • optional class methods to add to the class

get

(
  • property
)
Var

Defined in lib/quintus.js:1234

Return an individual property

Parameters:

  • property String

Returns:

Var:

value of the property

has

(
  • component
)
Boolean

Simple check to see if a component already exists on an object by searching for a property of the same name.

Parameters:

  • component String
    • name of component to test against

Returns:

Boolean:

inc

(
  • property
  • amount
)

Defined in lib/quintus.js:1211

Increment an individual property by amount, uses set internally

Parameters:

  • property String
  • amount Integer
    • amount to increment by

isA

(
  • className
)

Inherited from Q.Class: lib/quintus.js:683

See if a object is a specific class

Parameters:

  • className String
    • class to check against

off

(
  • event
  • [target]
  • [callback]
)

Inherited from Q.Evented: lib/quintus.js:870

Unbinds an event. Can be called with 1, 2, or 3 parameters, each of which unbinds a more specific listener.

Parameters:

  • event String
    • name of event
  • [target] Object optional
    • optionally limit to a specific target
  • [callback] Function optional
    • optionally limit to one specific callback

on

(
  • event
  • [target]
  • [callback]
)

Inherited from Q.Evented: lib/quintus.js:793

Binds a callback to an event on this object. If you provide a target object, that object will add this event to it's list of binds, allowing it to automatically remove it when it is destroyed.

Parameters:

  • event String
    • name or comma separated list of events
  • [target] Object optional
    • optional context for callback, defaults to the Evented
  • [callback] Function optional
    • callback (optional - defaults to name of event on context

reset

(
  • p
)

Defined in lib/quintus.js:1170

Resets the state to value p, triggers a reset event.

Parameters:

  • p Object
    • properties to reinitialize to

set

(
  • properties
  • [value]
)

Defined in lib/quintus.js:1186

Set one or more properties, trigger events on those properties changing.

Parameters:

  • properties Object or String
    • hash of properties to set, or property name
  • [value] Var optional
    • if setting 1 property, the value of that property

Example:

Q.state.set({ lives: 5, hitPoints: 4 }); // Triggers 3 events: change.lives, change.hitPoints, change

Q.state.set("lives",5); // Triggers 2 events: change.lives, change

trigger

(
  • event
  • [data]
)

Inherited from Q.Evented: lib/quintus.js:848

Triggers an event, passing in some optional additional data about the event.

Parameters:

  • event String
    • name of event
  • [data] Object optional
    • optional data to pass to the callback