PImage spritesheet;
int l, c;
PImage show;
PFont font;
int myFrame;
int myFrameRate=20;
float valeur;
boolean inverse=true;
boolean firstMousePress = false;
HScrollbar hs;
void setup() {
size(500, 300);
frameRate(myFrameRate);
l=4;
c=4;
spritesheet=loadImage("explosions.png");
font=createFont("whitrabt.ttf", 32);
textFont(font);
hs = new HScrollbar(20, height-20, width-40, 16, 1);
}
void draw() {
background(0);
show = exportImage(spritesheet, 4, 4, l, c);
image(show, 350, 50);
stroke(255);
fill(255);
myFrame=c+(l-1)*4;
text(myFrame, 350, 200);
fill(color(0, 0, 255));
stroke(color(0, 0, 255));
text(int(myFrameRate)+" images/s", width/2+30, height-40);
//show.save("data/explode"+myFrame+".png");
//if (myFrame==16) exit();
if (inverse) {
c--;
if (c==0) {
c=4;
l--;
if (l==0) {
l=1;
c=1;
inverse=false;
}
}
} else {
c++;
if (c==5) {
c=1;
l++;
if (l==5) {
inverse=true;
l=4;
c=4;
}
}
}
hs.update();
hs.display();
myFrameRate=int(map(hs.getPos(), 0, hs.swidth, 1, 50));
frameRate(myFrameRate);
}
PImage exportImage(PImage spritesheet, int nbLignes, int nbColonnes, int ligne, int colonne) {
image(spritesheet, 0, 0);
stroke(255);
noFill();
rect(0, 0, spritesheet.width, spritesheet.height);
int largeurExport=spritesheet.width/nbColonnes;
int hauteurExport=spritesheet.height/nbLignes;
rect(largeurExport*(colonne-1), hauteurExport*(ligne-1), largeurExport, hauteurExport);
return spritesheet.get(largeurExport*(colonne-1), hauteurExport*(ligne-1), largeurExport, hauteurExport);
}