I have a sprite variable, and when I draw it i use,
Code: Select all
Sprite.prototype.draw = function() {
if (!this.flashOn) {
ctx.drawImage(
this.tileset.image,
this.states[this.currentState].frames[this.states[this.currentState].currentFrame].split(',')[0] * this.tileset.tileWidth,
this.states[this.currentState].frames[this.states[this.currentState].currentFrame].split(',')[1] * this.tileset.tileHeight,
this.tileset.tileWidth,
this.tileset.tileHeight,
Math.round(this.x),
Math.round(this.y),
this.width,
this.height
);
}
}
Code: Select all
var spriteLeftAnim = new Animation(['1,1', '1,0'], 200);
var spriteRightAnim = new Animation(['0,1', '0,0'], 200);
var spriteUpAnim = new Animation(['2,1', '2,0'], 200);
var spriteDownAnim = new Animation(['3,1', '3,0'], 200);
var spriteDefinitions = {
turtle: new SpriteDefinition(
tilesets.turtle,
{
'left': spriteLeftAnim,
'right': spriteRightAnim,
'down': spriteDownAnim,
'up': spriteUpAnim
}, //Added by Oroton,
300, //200?
5,
true,
true
)
I have to create another function for to run solid objects and i use this
Code: Select all
var chestAnim = new staticObj(['3,0']);
chest: new SpriteDefinition(
tilesets.maptiles,
{
down: chestAnim
}
Code: Select all
function Animation(frames, frameDuration) {
this.frames = frames;
this.currentFrame = 0;
this.frameTimer = Date.now();
this.frameDuration = frameDuration;
}
function staticObj(frames) {
this.frames = frames;
this.currentFrame = 0;
}
Code: Select all
var chestAnim = new staticObj(['3,0']);
chest: new SpriteDefinition(
tilesets.maptiles,
{
down: chestAnim
}
Code: Select all
var chestAnim = new staticObj(['3,0']);
chest: new SpriteDefinition(
tilesets.maptiles,
{
down: '3,0'
}
Code: Select all
{
down: chest.frames{'3,0'}
}