SHARE
TWEET

Sprite.js

a guest Dec 9th, 2016 126 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Sprite(img)
  2. {
  3.     this.img = img;
  4.     this.rot = 0;
  5.     this.scl = createVector(1, 1);
  6.     this.pos = createVector(0, 0);
  7.     this.cnt = createVector(0, 0);
  8.     this.clp = {pos: createVector(0, 0), size: createVector(1, 1)};
  9.     this.col = color(255);
  10.    
  11.     this.draw = function()
  12.     {
  13.         var w = this.img.width * this.clp.size.x;
  14.         var h = this.img.height * this.clp.size.y;
  15.        
  16.         // Makes sure rotation and scaling happen around
  17.         // the correct axis of the sprite.
  18.         push();
  19.         translate(this.pos.x, this.pos.y);
  20.         rotate   (this.rot);
  21.         scale    (this.scl.x, this.scl.y);
  22.         translate(w * -this.cnt.x, h * -this.cnt.y);
  23.        
  24.         if (this.col != color(255))
  25.             tint(this.col);
  26.  
  27.         image
  28.         (
  29.             this.img,
  30.             this.img.width * this.clp.pos.x,
  31.             this.img.height * this.clp.pos.y,
  32.             w,
  33.             h,
  34.             0,
  35.             0,
  36.             w,
  37.             h
  38.         );
  39.         pop();
  40.        
  41.         //if (this.col != color(255))
  42.         //  noTint();
  43.     }
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top