Classes

Timeline

Sometimes you need a series of events to occur at specific times. Think of a space shooter for example, where waves of enemy ships come flying into the screen at predetermined times. In JackyJS, a Timeline allows you to create exactly this kind of functionality.

There are two different scopes for timelines, local and global. Local timelines are relative to the entity object they are attached to, which allows direct manipulation of their host object. Global timelines run in the context of the current active Room, and thus can manipulate all entities scoped to that Room.

Timelines are initialized in the GAME.initTimelines() global function. The following example shows you how:


	GAME.initTimelines(function(){
		var timeline1 = GAME.Timeline.create({
			name: 'timeline1',

			events: [
				{time: 2000, callback: function(obj){
					GAME.custom.funcs.enemyWaveOne();
				}},

				{time: 60000, callback: function(obj){
					GAME.custom.funcs.enemyWaveTwo();
				}},

				{time: 120000, callback: function(obj){
					GAME.custom.funcs.enemyWaveThree();		
				}}
			]
		});

		timeline1.onStart(function(obj){
			GAME.log('START of Timeline: ' + obj.name);
		});

		timeline1.onEnd(function(obj){
			GAME.log('END of Timeline: ' + obj.name);
		});

		timeline1.onDestroy(function(obj){
			GAME.log(obj.name + ' destroyed (via onDestroy)');
		});
	});

Event Properties

Name Type Description
* timeNumberthe time, in milliseconds before executing the corresponding callback function.
* callbackFunctionthe function to execute when corresponding time has elapsed.

Methods (static)

Name Parameter Type Description
createcreate a new Timeline object reference for later use. To use in a global context, use this class's static add method. To use in a local context, use an entity object's setTimeline method.
* options.nameStringthe name of the reference.
* options.eventsArraysee the Event Properties table.
options.relativeBooleanset TRUE, to make event time relative. (default: FALSE)
options.loopBooleanset TRUE to make timeline loop forever. (default: FALSE)
add* nameStringthe reference name of timeline to add to Room.
options.???Mixedsee create options; only relative and loop supported.
getnameStringthe name of global timeline object to return. Returns FALSE if not found.
destroy* nameStringthe name of global timeline object to destroy.
callbackFunctiona function to execute when timeline is destroyed.

Properties (object)

Name Type Description
entityInstanceStringthe instance reference of host entity, if local timeline. **read-only**
nameStringthe name of the timeline reference. **read-only**
startedBooleanis TRUE if timeline has already started. **read-only**
endedBooleanis TRUE if timeline has ended. **read-only**
pausedBooleanis TRUE if timeline has paused. **read-only**
relativeBooleanif set to TRUE, subsequent event time will be relative to the previous event time.
loopBooleanif set to TRUE, timeline will loop forever.

Methods (object)

Name Parameter Type Description
pausepause the timeline
resumeresume the timeline.
restartrestart the timeline from the beginning.
goto* indexNumberthe event array index to start at. (0 is the first)
delayNumberthe delay, in milliseconds, before starting at new index. ()default: 0
destroycallbackFunctiondestroy the timeline and optionally execute a function when done.

Events (object)

Name Parameter Type Description
onStartcallbackFunctionwhen the timeline starts.
onEndcallbackFunctionwhen the timeline ends. Will execute even if timeline is looped.
onDestroycallbackFunctionwhen the timeline is destroyed.