Class Clock

The Clock class is the basis on which many other classes throughout the shimi library rely upon to receive frequent and regular updates.

The clock contains a list of references to objects that implement IClockChild. Each time the clock receives an update, it forwards the message to all of its children.

Hierarchy

  • Clock

Constructors

  • Parameters

    • msPerTick: number = 5

      How many milliseconds from one tick to the next.

      Please note that the clock will not necessarily update exactly as often as defined here, but it should be pretty close.

      The default value is 5.

    Returns Clock

Properties

default: Clock = null

If set, then classes implementing the IClockChild interface should automatically add themselves to the default clock.

Accessors

  • get children(): IClockChild[]
  • List of objects that get updated by the clock each update cycle. It is strongly recommended not to add children directly through this list

    Returns IClockChild[]

  • get msPerTick(): number
  • How many milliseconds from one tick to the next.

    Please note that the clock will not necessarily update exactly as often as defined here, but it should be pretty close.

    Returns number

  • get running(): boolean
  • Returns whether the clock is already running.

    Returns boolean

  • get typeName(): string
  • Returns the name of this type. This can be used rather than instanceof which is sometimes unreliable.

    Returns string

Methods

  • Add a new object to receive clock updates to the end of the list. Returns the object that was added. This function is the same as addChildToEnd

    Parameters

    Returns IClockChild

  • Add a new object to receive clock updates to the start of the list. Returns the object that was added.

    Parameters

    Returns IClockChild

  • Add a new object to receive clock updates, positioned so it gets updates before the referenced object.

    Returns

    Returns the added child object.

    Parameters

    • child: IClockChild

      The object to be added to the update list

    • before: IClockChild

      The object for the child to be added in front of. The function will throw an error if this element can't be found

    Returns IClockChild

  • Add a new object to receive clock updates to the end of the list. Returns the object that was added.

    Parameters

    Returns IClockChild

  • Starts the clock running regular updates. Returns false if the clock was already running, otherwise returns true.

    Returns boolean

  • Stops the clock from running regular updates. Returns false if the clock was already stopped, otherwise returns true.

    Returns boolean

  • Calls the finish() method of all children which meet the passed in filter criteria.

    Parameters

    • filter: ((child: IClockChild) => boolean)

      Accepts a function which takes in an IClockChild, and returns a boolean, signifying whether the passed in IClockChild should be stopped.

    Returns void

  • Updates all active children which belong to the clock, as well removing any that have been stopped.

    You shouldn't really need to call this, once you call start(), this will begin getting called regularly anyway.

    Returns void

Generated using TypeDoc