Animation - Help! _ Beginner
in
Programming Questions
•
1 year ago
I am trying to make a butterfly flying.
I would like it to move the wings and then just to move a little bit in the air.
I don't know what I am doing wrong, but this is the code: my butterfly just moves like going crazy! That's no good. I would like to keep the frameRate at 60, I don't want to touch that.
I hope someone can help!
Thanks
- PImage bird1;
- PImage bird2;
- PImage bird3;
- PImage bird4;
- float randLocX = random(10, 100);
- float randLocY = random(10, 100);
- float myX = random(10, 100);
- float myY = random(10, 100);
- float animationSpeed=20;
- float animationSpeed2=20;
- void setup() {
- size(400, 400);
- background(255);
- bird1 = loadImage("bird1.png");
- bird2 = loadImage("bird2.png");
- bird3 = loadImage("bird3.png");
- bird4 = loadImage("bird4.png");
- }
- void draw() {
- background(255);
- drawABird();
- }
- void drawABird() {
- drawAFly(randLocX, randLocY);
- }
- void drawABirdA(float myX, float myY) {
- if (int(frameCount/animationSpeed)%6==0) {
- image(bird1, myX, myY);
- }
- if (int(frameCount/animationSpeed)%6==1) {
- image(bird2, myX, myY);
- }
- if (int(frameCount/animationSpeed)%6==2) {
- image(bird3, myX, myY);
- }
- if (int(frameCount/animationSpeed)%6==3) {
- image(bird2, myX, myY);
- }
- if (int(frameCount/animationSpeed)%6==4) {
- image(bird1, myX, myY);
- }
- if (int(frameCount/animationSpeed)%6==5) {
- image(bird4, myX, myY);
- }
- }
- void drawABirdB(float myX, float myY) {
- if (int(frameCount/animationSpeed)%6==0) {
- image(bird1, myX, myY);
- }
- if (int(frameCount/animationSpeed)%6==1) {
- image(bird2, myX, myY);
- }
- if (int(frameCount/animationSpeed)%6==2) {
- image(bird3, myX, myY);
- }
- if (int(frameCount/animationSpeed)%6==3) {
- image(bird2, myX, myY);
- }
- if (int(frameCount/animationSpeed)%6==4) {
- image(bird1, myX, myY);
- }
- if (int(frameCount/animationSpeed)%6==5) {
- image(bird4, myX, myY);
- }
- }
- void drawABirdC(float myX, float myY) {
- if (int(frameCount/animationSpeed)%6==0) {
- image(bird1, myX, myY);
- }
- if (int(frameCount/animationSpeed)%6==1) {
- image(bird2, myX, myY);
- }
- if (int(frameCount/animationSpeed)%6==2) {
- image(bird3, myX, myY);
- }
- if (int(frameCount/animationSpeed)%6==3) {
- image(bird2, myX, myY);
- }
- if (int(frameCount/animationSpeed)%6==4) {
- image(bird1, myX, myY);
- }
- if (int(frameCount/animationSpeed)%6==5) {
- image(bird4, myX, myY);
- }
- }
- void drawABirdD(float myX, float myY) {
- if (int(frameCount/animationSpeed)%6==0) {
- image(bird1, myX, myY);
- }
- if (int(frameCount/animationSpeed)%6==1) {
- image(bird2, myX, myY);
- }
- if (int(frameCount/animationSpeed)%6==2) {
- image(bird3, myX, myY);
- }
- if (int(frameCount/animationSpeed)%6==3) {
- image(bird2, myX, myY);
- }
- if (int(frameCount/animationSpeed)%6==4) {
- image(bird1, myX, myY);
- }
- if (int(frameCount/animationSpeed)%6==5) {
- image(bird4, myX, myY);
- }
- }
- void drawAFly(float myX, float myY) {
- myX = random(100, 200);
- myY = random(200, 250);
- if (int(frameCount/animationSpeed2)%10==0) {
- drawABirdA(myX, myY);
- }
- if (int(frameCount/animationSpeed2)%10==1) {
- drawABirdB(myX, myY);
- }
- if (int(frameCount/animationSpeed2)%10==2) {
- drawABirdC(myX, myY);
- }
- if (int(frameCount/animationSpeed2)%10==3) {
- drawABirdD(myX, myY);
- }
- if (int(frameCount/animationSpeed2)%10==4) {
- drawABirdA(myX, myY);
- }
- if (int(frameCount/animationSpeed2)%10==5) {
- drawABirdB(myX, myY);
- }
- if (int(frameCount/animationSpeed2)%10==6) {
- drawABirdC(myX, myY);
- }
- if (int(frameCount/animationSpeed2)%10==7) {
- drawABirdD(myX, myY);
- }
- }
1