Classes

Sprite

Sprite objects are essentially the meat-and-potatoes; they represent the majority of all the different types of entities commonly found in any game. In JackyJS, a Sprite is a high level entity object capable of handling input, events, collisions, effects, etc... A Sprite is derived from the Core > Entity object, which shares behaviors with Background, Dialog, and Text objects.

Sprite 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/sprites/main.png');
	});
	
	GAME.initAssets(function(){
		GAME.Sprite.asset({name:'jackyWalking', width:32, height:32, offsetX:3, images:[0,2,1,2]});
		GAME.Sprite.asset({name:'jackyStanding', width:32, height:32, offsetX:2});
		GAME.Sprite.asset({name:'jackyJumping', width:32, height:32, offsetY:2});
		GAME.Sprite.asset({name:'jackyFalling', width:32, height:40, y:128});
	});
	
	GAME.initEntities(function(){
		var player = GAME.Sprite.create('jacky',
		{
			name: 'player',
			originX: 0.5, originY: 0.5,
			width:32, height:32,
			hasGravity: true,
			bbox: {x1:8, y1:0, x2:24, y2:31} ,
			vars: { 
				IDLE: true, 
				LEFT: false, 
				RIGHT: true, 
				DOWN: true, 
				MOVE: 3 
			}
		}
	});
	
	GAME.initRooms(function(){
		var Level1 = GAME.Room.create({name:'Level1', transitionInDelay:500});

		Level1.onCreate(function(obj){
			obj.addSprite('player', {x:GAME.width/2, y:GAME.height/2, persistent:true});
		});
	});	

TIP: using the images property of the asset method, you can add as many extra arbitrary frames of animation as you wish.

Methods (static)

Name Parameter Type Description
assetinitializes a resource asset to be used as a reference in the creation of entities. If your spritesheet width/height is evenly divisible by your sprites' width and height, you will usually only need to use the offsetX and offsetY properties. If not, the x and y properties help you precisely pinpoint the starting point of any animation strips.
* srcStringsource filename of image resource to initialize. Path is not required. (default path: jackyjs/assets/sprites)
* options.nameStringname of asset.
options.widthNumberwidth of image. (default: 32)
options.heightNumberheight of image. (default: 32)
options.xNumberx position on spritesheet. (default: 0)
options.yNumbery position on spritesheet. (default: 0)
options.offsetXNumberx offset on spritesheet, by multiples of width. (default: 0)
options.offsetYNumbery offset on spritesheet, by multiples of height. (default: 0)
options.separatorNumberseparator width/height. (default: 0)
options.imagesArrayarray of indices for adjacent animation frames. (default: [0])
createcreates an entity object to be used for instantiating in Rooms.
* assetNameStringexisting asset name.
options.nameStringname of new entity. This is optional; if none provided, defaults to assetName.
options.imageIndexNumberthe starting image index. (default: 0)
options.imageLoopBooleanif set to TRUE, images will animate, if applicable. (default: TRUE)
options.imageDelayNumberimage animation frame delay, in milliseconds. (default: 100)

NOTE: if set to 0, images will not cycle, and must be advanced with imageIndex.
options.???MixedSee Core > Entity : Properties for available properties.
addinstantiates an entity object into the current Room.
* entityNameStringname of existing entity reference to instantiate.
* options.xNumberthe x coordinate to place in game.
* options.yNumberthe y coordinate to place in game.
options.???MixedSee Core > Entity : Properties for available properties.

Properties (object)

See Core > Entity : Properties for more properties.

Events (object)

See Core > Entity : Events for available events.