Classes

Room

Usually a game has multiple types of screens; ie, intro, menu, level select, game over, etc. In JackyJS you can think of a Room as a container for instantiating your entity objects. A Room is therefore analogous to a Stage, Scene, Screen, or Level; concepts you may have heard in other game engines. Rooms can have as many entities in them as you need, or none at all; for example, a Room might only be used to initialize some code before going to the next room.

The really cool part about Rooms, is they can Transition from one to the next! Rooms can have different transitionIn and transitionOut effects, as well as different delay intervals. By default, all rooms have a "fade" effect for their transition, but you can easily make your own. See Classes > Transition for more details.

TIP: Rooms are a major component to JackyJS; at least ONE is required to exist, otherwise your game won't run.

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


	GAME.initRooms(function(){
		var Intro = GAME.Room.create({name:'Intro', transitionInDelay:500'});
		var Level1 = GAME.Room.create({name:'Level1', transitionOutType:'curtain'});
		var GameOver = GAME.Room.create({name:'GameOver', transitionInType:'shutter'});

		Intro.onCreate(function(obj){
			obj.addBackground('intro', {x:0, y:0});
			obj.addSprite('btnStart', {x:GAME.width/2, y:GAME.height/2});
		});
		
		Intro.onStart(function(obj){
			GAME.Sound.play('bgMusic');
		});
				
		Level1.onCreate(function(obj){
			obj.addSprite('player', {x:64, y:GAME.height-64, persistent:true});
		});
		
		Level1.onUpdate(function(obj){
			// room controller code can go here.
		});
		
		Level1.onDestroy(function(obj){
			GAME.find({name:'player'}).each(obj){
				obj.vars.health = 100;
			};
		});
		
		GameOver.onCreate(function(obj){
			obj.addBackground('gameover', {x:0, y:0});
			obj.addSprite('btnMenu', {x:GAME.width/2, y:GAME.height/2});
		});
		
		GameOver.onStart(function(){
			// your game ending resets can go here.
		});
	});

Methods (static)

Name Parameter Type Description
create* options.nameStringname of room.
options.transitionInDelayNumberthe delay (in milliseconds) before the next room Transitions in. (default: null)
options.transitionInTypeStringthe Transition IN type. Values: 'fade', 'curtain', 'shutter'. (default: 'fade')
options.transitionOutTypeStringthe Transition OUT type. Values: 'fade', 'curtain', 'shutter'. (default: 'fade')
nextgoes to next room. If current room is last, does nothing.
prevgoes to previous room. If current room is first, does nothing.
goto* roomNameStringgoto a specific room.
getCurrentreturns an object reference to the current active room.
getNextreturns an object reference to the next room.
getPreviousreturns an object reference to the previous room.

Properties (object)

Name Type Description
nameStringthe name. **read-only**
STARTEDBooleanis TRUE if the room has finished loading. **read-only**

Methods (object)

Name Parameter Type Description
addSprite* entityNameStringname of Sprite entity to instantiate.
* options.xNumberx coordinate to place in game.
* options.yNumbery coordinate to place in game.
options.???Mixedsee Sprite class create options.
addBackground* entityNameStringname of Background entity to instantiate.
options.???Mixedsee Background class create options.
addDialog* entityNameStringname of Dialog entity to instantiate.
* options.xNumberx coordinate to place in game.
* options.yNumbery coordinate to place in game.
options.???Mixedsee Dialog class create options.
addParticleSystem* entityNameStringname of Particle System entity to instantiate.
* options.xNumberx coordinate to place in game.
* options.yNumbery coordinate to place in game.
options.???Mixedsee Particle class create options.
addText* entityNameStringname of Text entity to instantiate.
* options.xNumberx coordinate to place in game.
* options.yNumbery coordinate to place in game.
options.???Mixedsee Text class create options.
addTimeline* entityNameStringname of Timeline entity to instantiate.
options.???Mixedsee Timeline class create options.

Events (object)

Name Parameter Type Description
onCreatecallbackFunctionwhen the room is being created (all entities are created here).
onStartcallbackFunctionafter all room entities instantiated, and entity create events triggered.
onUpdatecallbackFunctionwhile room is updating.
onDestroycallbackFunctionwhen room is destroyed (only applies when going yo next/previous room).