Guest User

Untitled

a guest
May 25th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. var SpriteAnimation = new Class({
  2.  
  3. Implements: [Options, Events, Loop],
  4.  
  5. options: {
  6. frameWidth: 75,
  7. frames: 10,
  8. frameRate: 100,
  9. defaultPosition: {x: 0, y :0}
  10. },
  11.  
  12. jQuery: 'spriteAnimation',
  13.  
  14. initialize: function(selector, options){
  15. this.setOptions(options);
  16. this.setLoop(this.step, this.options.frameRate);
  17. this.element = jQuery(selector);
  18. var pos = this.options.defaultPosition.x + 'px ' + this.options.defaultPosition.y + 'px';
  19. this.element.css({'background-position': pos});
  20. this.startLoop();
  21. },
  22.  
  23. step: function(){
  24. var x = this.computeX();
  25. var y = this.computeY();
  26. this.element.css({'background-position': x+'px '+ y+'px'});
  27. return this;
  28. },
  29.  
  30. computeX: function(){
  31. this.loopCount = (this.loopCount == (this.options.frames)) ? this.options.defaultPosition.x : this.loopCount
  32. return -this.loopCount * this.options.frameWidth;
  33. },
  34.  
  35. computeY: function(){
  36. return this.options.defaultPosition.y;
  37. }
  38.  
  39. });
Add Comment
Please, Sign In to add comment