Ver Mensaje Individual
  #21 (permalink)  
Antiguo 31/01/2010, 23:25
Avatar de ClubIce
ClubIce
 
Fecha de Ingreso: diciembre-2008
Mensajes: 216
Antigüedad: 15 años, 4 meses
Puntos: 2
Respuesta: no detecta ID

lo que hize ahora fue igualar thus.count con frames.length, pero ahora no se porque no se mueve, ni tampoco me muertra ningun error:
Código Javascript:
Ver original
  1. <HTML>
  2.  <HEAD>
  3.   <TITLE>Ice Pokemon</TITLE>
  4.   <SCRIPT>
  5. Object.prototype.initialize = function(init){for(var prop in init)if(init.hasOwnProperty(prop)) this[prop] = init[prop];}
  6. $=function(i) {return document.getElementById(i)}
  7.  
  8. Sprite=function(image,width,height,hmargin,vmargin,hspace,vspace,rows,cols) {
  9.  this.numItems=rows*cols;
  10.  this.image=new Image()
  11.  this.image.src=image;
  12.  this.frames=new Array();
  13.  count=0;
  14.  for (i=0; i<cols; i++) {
  15.   for (j=0; j<rows; j++) {
  16.    x=vmargin+(width*j)+(vspace*j)
  17.    y=hmargin+(height*i)+(hspace*i)
  18.    this.frames[count]={x:x,y:y}
  19.    count++
  20.   }
  21.  }
  22.  this.height=height;
  23.  this.width=width
  24. }
  25.  
  26. Animation=function(spr,spd) {
  27.  this.initialize({
  28.   sprite:spr,
  29.   speed:spd,
  30.   frames:[],
  31.   timer:null,
  32.   count:0,
  33.   id:null
  34.  });
  35. }
  36. Animation.prototype={
  37.  addFrame: function (id) {
  38.   spr=this
  39.   i=(!this.frames.length)? 0: this.frames.length++
  40.   this.frames[i]={
  41.    id:id,
  42.    sprite:"url('"+spr.sprite.image.src+"') -"+spr.sprite.frames[id].x+"px -"+spr.sprite.frames[id].y+"px"
  43.   }
  44.  },
  45.  drawAnimation:function (con, id) {
  46.   image=document.createElement('img')
  47.   image.setAttribute('src','sprites/empy.gif')
  48.   image.setAttribute('style',"background:"+this.frames[0].sprite)
  49.   image.setAttribute('class','animation')
  50.   image.setAttribute('width',this.sprite.width)
  51.   image.setAttribute('height',this.sprite.height)
  52.   image.setAttribute('id',id)
  53.   con.appendChild(image)
  54.   this.id=image
  55.   var that = this;
  56.   this.timer=setInterval(function(){that.play();},this.speed);
  57.  },
  58.  play:function() {
  59.   //this.count=(this.count==this.frames.length)? 0:this.count++
  60.   this.id.style.background=this.frames[this.count].sprite
  61.   if (this.count==this.frames.length-1) {this.count=0} else {this.count++}
  62.  }
  63. }
  64. avatar=new Sprite('sprites/avatars/ash_walking.gif',30,38,0,0,0,0,1,12);
  65. aniAvatar=new Animation(avatar,100);
  66. aniAvatar.addFrame(0);
  67. aniAvatar.addFrame(1);
  68. aniAvatar.addFrame(0);
  69. aniAvatar.addFrame(2);
  70. window.onload=function() {aniAvatar.drawAnimation($('con'),'IMGavatar')}
  71.  
  72.   </SCRIPT>
  73.  </HEAD>
  74.  <BODY>
  75.  <DIV ID="con"></DIV>
  76.  </BODY>
  77. </HTML>