Loading more pictures from a class
in
Contributed Library Questions
•
7 months ago
Hey,
So I basicly want to import more pictures (in this case birds from my class Sif) and I'm not findng the right way to do it.
I want the birds to be able to fly in different direction from the begining. Does anyone now how to do that or just guide me in the right direction?
Atm. I just load one bird.
So I basicly want to import more pictures (in this case birds from my class Sif) and I'm not findng the right way to do it.
I want the birds to be able to fly in different direction from the begining. Does anyone now how to do that or just guide me in the right direction?
Atm. I just load one bird.
- import gifAnimation.*;
PImage[] animation;
PImage bg;
Gif loopingGif;
Gif loopingGif2;
Sif b = new Sif();
void setup() {
size(900, 675);
frameRate(40);
fill(128);
loopingGif = new Gif(this, "birdie.gif");
loopingGif.loop();
loopingGif2 = new Gif(this, "birdie2.gif");
loopingGif2.loop();
b.setup();
bg = loadImage("mountsmall.jpg");
}
void draw() {
background(bg);
fill(0, 50);
noStroke();
rect(0, 0, width, height);
fill(0);
b.draw();
b.update();
} - class Sif {
PVector pos = new PVector();
PVector vel = new PVector();
float r = 5;
void setup() {
pos.set(width/5, height/5, 0); //var den startar
vel.x = 3; // hastighet i x och yled
vel.y = 2;
}
void draw() {
if(vel.x>0) {
image(loopingGif2, pos.x, pos.y);
}
else{
image(loopingGif, pos.x, pos.y);
}
}
void update() {
pos.add(vel);
if (pos.x+r>width-450 || pos.x-r<50) vel.x=-vel.x;
if (pos.y+r>height-500 || pos.y-r<0) vel.y=-vel.y;
}
}
1