AnimationLayer.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /// <reference path="../Elements.ts" />
  2. // parseInt(Elements.getStyle(".anims-orcNotStand").style.width.slice(0, -2))
  3. class AnimationLayer {
  4. private cStep = 0;
  5. private totalSteps = 9;
  6. private frameSize = 200;
  7. private el = document.createElement("a");
  8. constructor (filename : string, layer? : number) {
  9. this.el.classList.add("sceneAnimation");
  10. if (layer != undefined) {
  11. this.el.style.zIndex = layer.toString();
  12. }
  13. let style = Elements.getStyle(".anims-" + filename);
  14. if (style == undefined || style.width == undefined) {
  15. console.error("Animation " + filename + " not found.");
  16. } else {
  17. let height = (parseInt(style.height.slice(0,-2)));
  18. this.frameSize = height;
  19. this.totalSteps = (parseInt(style.width.slice(0,-2)) / height);
  20. }
  21. this.el.classList.add("anims-" + filename);
  22. this.updateSize();
  23. }
  24. public updateSize () {
  25. this.el.style.transform = "scale(" + (Elements.AnimationHandler.spriteSize / this.frameSize) + ")";
  26. this.el.style.width = this.frameSize + "px";
  27. this.el.style.height = this.frameSize + "px";
  28. this.el.style.marginLeft = "-" + this.frameSize/2 + "px";
  29. this.el.style.marginTop = "-" + this.frameSize/2 + "px";
  30. }
  31. public updateSprite (percentage : number) {
  32. this.cStep = Math.floor(percentage * this.totalSteps);
  33. this.el.style.backgroundPositionX = "-" + (this.cStep * this.frameSize) + "px";
  34. }
  35. public getElement () {
  36. return this.el;
  37. }
  38. }
  39. /**
  40. Planning...
  41. - Player Spritesheets need to have certain important markers down, set as connect points.
  42. ----- Top of Head coordinates (used for "stunned" effects, whatever)
  43. ----- Crotch coordinates
  44. ----- Facing Direction
  45. ----- Mouth Coordinates
  46. These are, of course, connection points.
  47. **/