Código Javascript
:
Ver originalAnimation=function(spr,spd) {
this.initialize({
sprite:spr,
speed:spd,
frames:[],
timer:null,
count:0,
id:null
});
}
Animation.prototype={
addFrame: function (id) {
spr=this
this.frames[frames.length]={
id:id,
sprite:"url('"+spr.sprite.image.src+"') "+spr.sprite.frames[id].x+"px "+spr.sprite.frames[id].y+"px;"
}
},
drawAnimation:function (con, id) {
image=document.createElement('img')
image.setAttribute('src','sprites/empy.gif')
image.setAttribute('style',"background:"+this.frames[0].sprite)
image.setAttribute('class','animation')
image.setAttribute('width',this.sprite.width)
image.setAttribute('height',this.sprite.height)
image.setAttribute('id',id)
this.id=image
con.appendChild(image)
this.timer=setInterval(this.play,this.speed);
},
play:function() {
if (this.count=this.frames.length) {
this.count=0
} else {
this.count++
}
this.id.style.background=this.frames[this.count]
}
}