new Timer(viewer, autoDestroy)
Timer utility that work with FORGE.Clock.
Parameters:
Name | Type | Description |
---|---|---|
viewer |
FORGE.Viewer | The FORGE.Viewer reference. |
autoDestroy |
boolean | Does the timer will autodestroy on time complete? |
- Source:
Extends
Members
(readonly) alive :boolean
Get the alive flag value of the object.
Type:
- boolean
- Inherited From:
- Source:
(readonly) autoDestroy :boolean
Get the auto destroy value.
Type:
- boolean
- Source:
(readonly) className :string
Get the class name of the object.
Type:
- string
- Inherited From:
- Source:
data :*
Get and set any custom data you want to associate to this object.
Type:
- *
- Inherited From:
- Source:
debug :boolean
Get and set the debug flag.
Type:
- boolean
- Inherited From:
- Source:
(readonly) duration :number
The duration in ms remaining until the next event will occur.
Type:
- number
- Source:
(readonly) length :number
The number of pending events in the queue.
Type:
- number
- Source:
(readonly) ms :number
The duration in milliseconds that this Timer has been running for.
Type:
- number
- Source:
(readonly) next :number
Get the time tick at which the next event will occur.
Type:
- number
- Source:
(readonly) onComplete :FORGE.EventDispatcher
Get the "onComplete" event FORGE.EventDispatcher of the timer.
Type:
- Source:
(readonly) onDestroy :FORGE.EventDispatcher
Get the onDestroy FORGE.EventDispatcher, this event is emitted at the end of the destroy sequence.
Type:
- Inherited From:
- Source:
(readonly) onPause :FORGE.EventDispatcher
Get the "onPause" event FORGE.EventDispatcher of the timer.
Type:
- Source:
(readonly) onResume :FORGE.EventDispatcher
Get the "onResume" event FORGE.EventDispatcher of the timer.
Type:
- Source:
(readonly) onStart :FORGE.EventDispatcher
Get the "onStart" event FORGE.EventDispatcher of the timer.
Type:
- Source:
(readonly) onStop :FORGE.EventDispatcher
Get the "onStop" event FORGE.EventDispatcher of the timer.
Type:
- Source:
(readonly) seconds :number
The duration in seconds that this Timer has been running for.
Type:
- number
- Source:
(readonly) tags :Array
Get the tags associated to this object.
Type:
- Array
- Inherited From:
- Source:
(readonly) uid :string
Get the uid of the object.
Type:
- string
- Inherited From:
- Source:
warning :boolean
Get and set the warning flag.
Type:
- boolean
- Inherited From:
- Source:
Methods
add(delay, callback, callbackContext, …args) → {FORGE.TimerEvent}
Add an event in the timer
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
delay |
number | The delay to call the event. | |
callback |
function | The callback function. | |
callbackContext |
Object | The context for the callback function. | |
args |
* |
<repeatable> |
Arguments to pass to the timer event handler |
- Source:
Returns:
Returns the created event.
- Type
- FORGE.TimerEvent
create(delay, loop, repeatCount, callback, callbackContext, args) → {FORGE.TimerEvent}
Create an event in the timer.
Parameters:
Name | Type | Description |
---|---|---|
delay |
number | The delay to call the event. |
loop |
boolean | Must be looped? |
repeatCount |
number | Number of repetition. |
callback |
function | The callback function. |
callbackContext |
Object | The context for the callback function. |
args |
Array.<*> | List of arguments. |
- Source:
Returns:
Returns the created event.
- Type
- FORGE.TimerEvent
destroy()
Destroy method.
- Overrides:
- Source:
log(value)
Basic log method, log a string in the console if debug is enabled.
Parameters:
Name | Type | Description |
---|---|---|
value |
* | The value you want to log in the console. |
- Inherited From:
- Source:
loop(delay, callback, callbackContext) → {FORGE.TimerEvent}
Loop an event in the timer.
Parameters:
Name | Type | Description |
---|---|---|
delay |
number | The delay to call the event. |
callback |
function | The callback function. |
callbackContext |
Object | The context for the callback function. |
- Source:
Returns:
Returns the created event.
- Type
- FORGE.TimerEvent
pause()
Pause the timer.
- Source:
remove(event) → {boolean}
Remove an event from the timer.
Parameters:
Name | Type | Description |
---|---|---|
event |
FORGE.TimerEvent | The event to remove. |
- Source:
Returns:
Returns true if event has been removed, if not, returns false.
- Type
- boolean
repeat(delay, repeatCount, callback, callbackContext) → {FORGE.TimerEvent}
Repeat an event in the timer.
Parameters:
Name | Type | Description |
---|---|---|
delay |
number | The delay to call the event. |
repeatCount |
number | The number of repetition. |
callback |
function | The callback function. |
callbackContext |
Object | The context for the callback function. |
- Source:
Returns:
Returns the created event.
- Type
- FORGE.TimerEvent
resume()
Resume the timer.
- Source:
start()
Start the timer.
- Source:
stop(clearopt)
Stop the timer.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
clear |
boolean |
<optional> |
true | Clear the events list. |
- Source:
update(time)
Update the timer from the main loop.
Parameters:
Name | Type | Description |
---|---|---|
time |
number | The current time. |
- Source:
warn(valuenullable)
Basic warn method, log a warn string in the console if warning is enabled.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
value |
string | Object |
<nullable> |
The value you want to warn in the console. |
- Inherited From:
- Source: