Loading new gif when reaching end of screen
in
Contributed Library Questions
•
7 months ago
Hey,
Im making a bird just bouncing around from side to side. I want to have two pictures, one that loads when it flies in one direction and the other one when it flies back.
Does anyone know what i'm doing wrong here? Atm. it works but when it reaches the end it just flips the image for 1/10th second and then back to same image.
I'm using the gifAnimation-library.
Im making a bird just bouncing around from side to side. I want to have two pictures, one that loads when it flies in one direction and the other one when it flies back.
Does anyone know what i'm doing wrong here? Atm. it works but when it reaches the end it just flips the image for 1/10th second and then back to same image.
I'm using the gifAnimation-library.
- import gifAnimation.*;
PImage[] animation;
Gif loopingGif;
Gif loopingGif2;
Sif b = new Sif();
void setup() {
size(640, 440);
frameRate(40);
fill(128);
loopingGif = new Gif(this, "bird.gif");
loopingGif.loop();
loopingGif2 = new Gif(this, "bird2.gif");
loopingGif2.loop();
b.setup();
}
void draw() {
background(255);
fill(0, 50);
noStroke();
rect(0, 0, width, height);
b.draw();
b.update();
}
- class Sif {
PVector pos = new PVector();
PVector vel = new PVector();
float r = 2;
void setup() {
//pos.set(width/2, height/2, 0);
pos.set(2, 2, 0);
vel.x = 2;
vel.y = 2;
}
void draw() {
if(pos.x+r>width-150){
image(loopingGif, pos.x, pos.y);
}
if(pos.x+r>width-640){
image(loopingGif2, pos.x, pos.y);
}
}
void update() {
pos.add(vel);
if (pos.x+r>width-150 || pos.x-r<0) vel.x=-vel.x;
if (pos.y+r>height-100 || pos.y-r<0) vel.y=-vel.y;
}
}
1