Advertisement
JoshuaDavis

twitch / spritesheet

Feb 20th, 2019
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.40 KB | None | 0 0
  1. int    stageW   = 1920;
  2. int    stageH   = 981;
  3. color  clrBG    = #999999;
  4. String pathDATA = "../../data/";
  5.  
  6. // ********************************************************************************************************************
  7.  
  8. PImage ss;
  9. int    ssW      = 980;
  10. int    ssH      = 980;
  11. int    ssCols   = 5;
  12. int    ssRows   = 5;
  13. int    ssMax    = ssCols * ssRows;
  14. int    ssCellW  = ssW/ssCols;
  15. int    ssCellH  = ssH/ssRows;
  16.  
  17. int    ssCount  = 0;
  18. int    ssX, ssY; // store/update x,y positions
  19.  
  20. int    speedMin = 0;
  21. int    speedMax = 2;
  22.  
  23. // ********************************************************************************************************************
  24.  
  25. void settings() {
  26.     size(stageW, stageH, P3D);
  27.     // noSmooth(); // does nothing says joshua davis
  28. }
  29.  
  30. void setup(){
  31.     // aliasing to anti-aliasing / pixel perfect to blurry
  32.     // 2 (nearest), 3 (linear), 4 (bilinear), and 5 (trilinear):
  33.     hint(DISABLE_TEXTURE_MIPMAPS);
  34.     ((PGraphicsOpenGL)g).textureSampling(2);
  35.  
  36.     ss = loadImage(pathDATA + "spritesheet.png");
  37. }
  38.  
  39. void draw(){
  40.     background(clrBG);
  41.  
  42.     // lets visualize the sprite sheet
  43.     image(ss, 0, 0, ssW, ssH);
  44.  
  45.     // lets visualize the texture selection moving trough the spritesheet
  46.     if (++speedMin%speedMax==0) {
  47.         ssX = (ssCount%ssCols) * ssCellW;
  48.         ssY = (ssCount/ssRows) * ssCellH;
  49.         ssCount = ++ssCount%ssMax;
  50.     }
  51.  
  52.     strokeWeight(1);
  53.     stroke(#FF3300);
  54.     noFill();
  55.     rect(ssX, ssY, ssCellW, ssCellH);
  56.  
  57.     // create an object that performs the sprite sheet animation
  58.  
  59.     strokeWeight(0);
  60.     noStroke();
  61.     noFill();
  62.     noTint();
  63.  
  64.     pushMatrix();
  65.         translate(stageW/2, stageH/2, 0);
  66.  
  67.         pushMatrix();
  68.             translate( (stageW-ssW)/2, 0);
  69.             scale(ssCellW); // 196 (980/5)
  70.  
  71.             beginShape(QUADS);
  72.                 texture(ss);
  73.                 vertex( -(0.5), -(0.5), 0,   ssX,                 ssY);
  74.                 vertex(  (0.5), -(0.5), 0,   ssX+ssCellW,         ssY);
  75.                 vertex(  (0.5),  (0.5), 0,   ssX+ssCellW, ssY+ssCellH);
  76.                 vertex( -(0.5),  (0.5), 0,   ssX,         ssY+ssCellH);
  77.             endShape(CLOSE);
  78.         popMatrix();
  79.  
  80.     popMatrix();
  81.  
  82.  
  83.  
  84.  
  85.     // pushMatrix();
  86.     //  translate(982, 0);
  87.     //  // src, srcX, srcY, srcW, srcH, destX, destY, destW, destH
  88.     //  copy(ss,   ssX,ssY,ssCellW,ssCellH,   0,0,ssCellW,ssCellH);
  89.     // popMatrix();
  90.  
  91.     surface.setTitle( int(frameRate) + " FPS" );
  92. }
  93.  
  94. // ********************************************************************************************************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement