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.name | String | name of room. |
options.transitionInDelay | Number | the delay (in milliseconds) before the next room Transitions in. (default: null) | |
options.transitionInType | String | the Transition IN type. Values: 'fade', 'curtain', 'shutter'. (default: 'fade') | |
options.transitionOutType | String | the Transition OUT type. Values: 'fade', 'curtain', 'shutter'. (default: 'fade') | |
next | goes to next room. If current room is last, does nothing. | ||
prev | goes to previous room. If current room is first, does nothing. | ||
goto | * roomName | String | goto a specific room. |
getCurrent | returns an object reference to the current active room. | ||
getNext | returns an object reference to the next room. | ||
getPrevious | returns an object reference to the previous room. |
Properties (object)
Name | Type | Description |
---|---|---|
name | String | the name. **read-only** |
STARTED | Boolean | is TRUE if the room has finished loading. **read-only** |
Methods (object)
Name | Parameter | Type | Description |
---|---|---|---|
addSprite | * entityName | String | name of Sprite entity to instantiate. |
* options.x | Number | x coordinate to place in game. | |
* options.y | Number | y coordinate to place in game. | |
options.??? | Mixed | see Sprite class create options. | |
addBackground | * entityName | String | name of Background entity to instantiate. |
options.??? | Mixed | see Background class create options. | |
addDialog | * entityName | String | name of Dialog entity to instantiate. |
* options.x | Number | x coordinate to place in game. | |
* options.y | Number | y coordinate to place in game. | |
options.??? | Mixed | see Dialog class create options. | |
addParticleSystem | * entityName | String | name of Particle System entity to instantiate. |
* options.x | Number | x coordinate to place in game. | |
* options.y | Number | y coordinate to place in game. | |
options.??? | Mixed | see Particle class create options. | |
addText | * entityName | String | name of Text entity to instantiate. |
* options.x | Number | x coordinate to place in game. | |
* options.y | Number | y coordinate to place in game. | |
options.??? | Mixed | see Text class create options. | |
addTimeline | * entityName | String | name of Timeline entity to instantiate. |
options.??? | Mixed | see Timeline class create options. |
Events (object)
Name | Parameter | Type | Description |
---|---|---|---|
onCreate | callback | Function | when the room is being created (all entities are created here). |
onStart | callback | Function | after all room entities instantiated, and entity create events triggered. |
onUpdate | callback | Function | while room is updating. |
onDestroy | callback | Function | when room is destroyed (only applies when going yo next/previous room). |