Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var SpriteAnimation = new Class({
- Implements: [Options, Events, Loop],
- options: {
- frameWidth: 75,
- frames: 10,
- frameRate: 100,
- defaultPosition: {x: 0, y :0}
- },
- jQuery: 'spriteAnimation',
- initialize: function(selector, options){
- this.setOptions(options);
- this.setLoop(this.step, this.options.frameRate);
- this.element = jQuery(selector);
- var pos = this.options.defaultPosition.x + 'px ' + this.options.defaultPosition.y + 'px';
- this.element.css({'background-position': pos});
- this.startLoop();
- },
- step: function(){
- var x = this.computeX();
- var y = this.computeY();
- this.element.css({'background-position': x+'px '+ y+'px'});
- return this;
- },
- computeX: function(){
- this.loopCount = (this.loopCount == (this.options.frames)) ? this.options.defaultPosition.x : this.loopCount
- return -this.loopCount * this.options.frameWidth;
- },
- computeY: function(){
- return this.options.defaultPosition.y;
- }
- });
Add Comment
Please, Sign In to add comment