Classes

Background

Most games need a background graphic layer, but in some cases, a background color can suffice. In cases where there are no background layers, the background color will be whatever hex value you specified via the bgColor property in the GAME.execute() function. The default background color is black (#000000).

Background images are first preloaded, then assets initialized, then entities created, then objects instantiated, in Rooms. The following example shows you how:


	GAME.initPreload(function(){
		GAME.Preloader.images.push('jackyjs/assets/backgrounds/forest.png');
	});
	
	GAME.initAssets(function(){
		GAME.Background.asset('forest.png', {name:'forest', width:640, height:240});
	});
	
	GAME.initEntities(function(){
		var forest = GAME.Background.create('forest', {tile:true});
	});
	
	GAME.initRooms(function(){
		var Level1 = GAME.Room.create({name:'Level1', transitionInDelay:500});

		Level1.onCreate(function(obj){
			obj.addBackground('forest', {persistent:true});
		});
	});

NOTE: when adding Backgrounds in the initRooms function, the Room class function addBackground is used for adding backgrounds, instead of GAME.Background.add(), because the engine does not yet know what Room we are working in. In all other contexts the normal Background class function is used.

Backgrounds are derived from the core Entity class. They share the same properties, methods, and events with many other types of objects. Backgrounds are thus first class objects! What this means is that a background entity can do pretty much the same stuff that a Sprite entity can. For example, you can make a Background entity rotate, scale, tint, slide, fade, etc..

TIP: Background entities cannot record any mouse events because they generally take up the whole screen. Use the Global mouse events for this type of functionality.

Methods (static)

Name Parameter Type Description
assetinitializes a resource asset to be used as a reference in the creation of entities.
* srcStringsource filename of image resource to initialize. Path is not required. (default path: jackyjs/assets/backgrounds)
* options.nameStringname of asset.
options.widthNumberwidth of image. (default: GAME.width)
options.heightNumberheight of image. (default: GAME.height)
createcreates an entity object to be used for instantiating in Rooms. When tile is set to TRUE and the hspeed is not 0, the background will scroll and tile seamlessly.
* assetNameStringexisting asset name.
options.nameStringname of new entity. This is optional; if none provided, defaults to assetName.
options.tileBooleanif set to TRUE, will tile both horizontally and vertically. (default: FALSE)
options.???Mixedsee Core > Entity : Properties for available properties.
addinstantiates an entity object into the current Room.
* entityNameStringname of existing entity reference to instantiate.
options.???Mixedsee Core > Entity > Properties for available properties.

Properties (object)

See Core > Entity : Properties for available properties.

Events (object)

See Core > Entity : Events for available events.