Class: core/HostObject

core/HostObject(optionsopt)

Object that manages access to all Host features. Contains a reference to
engine-specific visuals if applicable.

Constructor

new core/HostObject(optionsopt)

Parameters:
Name Type Attributes Description
options Object <optional>

Options for the host.

Properties
Name Type Attributes Description
owner Object <optional>

Optional engine-specific owner of the host.

Properties:
Name Type Description
EVENTS Object

Built-in messages that the Messenger emits.

Properties
Name Type Attributes Default Description
update string <optional>
'onUpdate'

Message that is emitted after
each call to update.

addFeature string <optional>
'onAddFeature'

Message that is emitted
after each call to addFeature.

removeFeature string <optional>
'onRemoveFeature'

Message that is emitted
after each call to removeFeature.

Extends

Members

(readonly) deltaTime :number

Gets the amount of time in milliseconds since update was last called.

Type:
  • number

(readonly) id :string

Gets the string id of the object.

Type:
  • string
Overrides:

(readonly) now :number

Gets the current time in milliseconds.

Type:
  • number

(readonly) owner :Object

Gets the engine owner object of the host.

Type:
  • Object

Methods

addFeature(FeatureClass, forceopt, …args) → {boolean}

Instantiate a new Host feature and store it. Features must inherit from
AbstractHostFeature.

Parameters:
Name Type Attributes Default Description
FeatureClass Class

Class that will instantiate the feature. Must
extend AbstractHostFeature.

force boolean <optional>
false

Whether or not to overwrite an existing
feature if one of this type already exists on the object.

args any <repeatable>

Additional arguments to pass to the FeatureClass
constructor. The HostObject will always be passed as the first argument.

Returns:
  • Whether or not a feature was successfully added.
Type
boolean

emit(message, valueopt)

Send a message, causing listener functions for the message on this object
to be executed.

Parameters:
Name Type Attributes Description
message string

The message to emit.

value any <optional>

Optional argument to pass to listener callbacks.

Overrides:

hasFeature(typeName) → {boolean}

Indicate whether a specified feature is installed on the host.

Parameters:
Name Type Description
typeName string

Name of the type of feature to look for.

Returns:
Type
boolean

listenTo(message, callback)

Execute a function when a message is received for this object.

Parameters:
Name Type Description
message string

The message to listen for.

callback function

Function to execute once the message is received.

Overrides:

listFeatures() → {Array.<string>}

List the names of the features installed on the host.

Returns:
Type
Array.<string>

removeFeature(typeName) → {boolean}

Remove a feature from the object.

Parameters:
Name Type Description
typeName string

Name of the type of feature to remove.

Returns:
  • Whether or not a feature was successfully removed.
Type
boolean

stopListening(message, callbackopt)

Prevent a function from being executed when a message is received for this
object.

Parameters:
Name Type Attributes Description
message string

The message to stop listening for.

callback function <optional>

Optional callback to remove. If none is defined,
remove all callbacks for the message.

Overrides:

stopListeningByRegexp(regexp, callbackopt)

De-register callback(s) from being executed when messages matching the given
regular expression are received.

Parameters:
Name Type Attributes Description
regexp Regexp

regexp - The regular expression to filter messages with.

callback function <optional>

Optional callback to remove. If none is defined,
remove all callbacks for messages matching the regular expression.

Overrides:

stopListeningToAll()

Prevent any functions from being executed when any message is received for
this object.

Overrides:

update()

This function should be called in the engine's render loop. Executes update
loops for all features.

wait(secondsopt, optionsopt) → {Deferred}

Return a deferred promise that will wait a given number of seconds before
resolving. The host will continuously update the wait promise during the
update loop until it resolves.

Parameters:
Name Type Attributes Default Description
seconds number <optional>
0

Number of seconds to wait before resolving.

options Object <optional>

Optional options object

Properties
Name Type Attributes Description
onFinish function <optional>

Callback to execute once the wait time
is met.

onProgress function <optional>

Callback to execute each time the wait
time progresses towards the target number of seconds. The amount of progress
as a 0-1 percentage is passed as an argument.

onCancel function <optional>

Callback to execute if the user cancels
the wait before completion.

onError function <optional>

Callback to execute if the wait stops
because an error is encountered. The error message is passed as a parameter.

Returns:
Type
Deferred