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
createoptions.nameStringname of alarm. (default: auto-generated string)
* options.timeNumbertime duration. (default: 1000ms)
options.pausableBooleanif FALSE, cannot be paused. (default: TRUE)
options.repeatBooleanif TRUE, repeats forever. (default: FALSE)
callbackFunctionfunction to execute when alarm is done.
destroy* nameStringname of alarm reference to destroy.
callbackFunctionfunction to execute when destroyed.