Classes
Alarm
An alarm is similar to the way a Javascript timeout()
or interval()
works. The difference is that an alarm is actually tied to the internal logic of the game engine. For example, if the user pauses the game, you may not want an alarm to continue ticking away. JackyJS handles both timeout and interval style alarms.
There are two contexts for alarms: local and global. A local alarm is one that executes in the scope of an entity, that is, once the entity no longer exists, neither does its alarm. A global alarm persists until it is stopped or destroyed, even when going from room to room. The following example shows both types:
// global alarm
GAME.Alarm.create({name:'rotateCarrots', time:1000, repeat:true}, function(){
GAME.find({instanceOf:'carrot'}).each(function(obj){
obj.rotate({degrees:10});
});
});
// local alarm
var carrot = GAME.Sprite.create('carrot', {x:GAME.width/2, y:GAME.height/2});
carrot.onCreate(function(obj){
obj.setAlarm({name:'rotate', time:1000, repeat:true}, function(obj){
obj.rotate({degrees:10});
});
});
Methods (static)
Name | Parameter | Type | Description |
---|---|---|---|
create | options.name | String | name of alarm. (default: auto-generated string) |
* options.time | Number | time duration. (default: 1000ms) | |
options.pausable | Boolean | if FALSE, cannot be paused. (default: TRUE) | |
options.repeat | Boolean | if TRUE, repeats forever. (default: FALSE) | |
callback | Function | function to execute when alarm is done. | |
destroy | * name | String | name of alarm reference to destroy. |
callback | Function | function to execute when destroyed. |