craftyjs.github.com

Crafty Time

Back to top

.delay

public this.delay(Function callback, Number delay)

callback
Method to execute after given amount of milliseconds
delay
Amount of milliseconds to execute the method
repeat
How often to repeat the delayed function. A value of 0 triggers the delayed

function exactly once. A value n > 0 triggers the delayed function exactly n+1 times. A value of -1 triggers the delayed function indefinitely.

The delay method will execute a function after a given amount of time in milliseconds.

It is not a wrapper for setTimeout.

If Crafty is paused, the delay is interrupted with the pause and then resume when unpaused

If the entity is destroyed, the delay is also destroyed and will not have effect.

Example

console.log("start");
this.delay(function() {
         console.log("100ms later");
}, 100, 0);