This site requires JavaScript, please enable it in your browser!
Greenfoot back
SlayGirlSlay
SlayGirlSlay wrote ...

2022/4/7

Animation freezes on last image

SlayGirlSlay SlayGirlSlay

2022/4/7

#
So Idk how long it will take for someone to respond to this but I see my teacher again tomorrow but I really need to see why my cat freezes on one frame. It works when I run the game and he works for a moment then freezes in his last frame and wont change at all. Why is that? public class Cat extends Actor { private GreenfootImage run0r = new GreenfootImage("pixil-frame-0 (3).png"); private GreenfootImage run1r = new GreenfootImage("pixil-frame-0 (4).png"); private GreenfootImage run2r = new GreenfootImage("pixil-frame-0 (5).png"); private GreenfootImage run3r = new GreenfootImage("pixil-frame-0 (6).png"); private GreenfootImage run4r = new GreenfootImage("pixil-frame-0 (7).png"); private GreenfootImage run5r = new GreenfootImage("pixil-frame-0 (8).png"); private GreenfootImage run6r = new GreenfootImage("pixil-frame-0 (9).png"); private int frame = 1; private int animationCounter = 4; public void act() { checkKeypress(); animationCounter = animationCounter +1; } public void checkKeypress() { if (Greenfoot.isKeyDown("up")) { setLocation(getX(), getY()-4); animateUp(); } if (Greenfoot.isKeyDown("left")) { setLocation(getX()-4, getY()); animateLeft(); } if (Greenfoot.isKeyDown("right")) { setLocation(getX()+4, getY()); if(animationCounter % 6 == 0) animateRight(); } if (Greenfoot.isKeyDown("down")) { setLocation(getX(), getY()+4 ); animateDown(); } } public void animateRight() { if(frame == 1) { setImage(run2r); } else if(frame == 2) { setImage (run3r); } else if(frame == 3) { setImage (run4r); } else if(frame == 4) { setImage (run5r); } else if(frame == 5) { setImage (run6r); frame = 1; return; } frame ++; } public void animateLeft() { if(frame == 1) { setImage(run1r); frame = 1; return; } frame ++; } public void animateUp() { if(frame == 1) { setImage(run0r); frame = 1; return; } frame ++; } public void animateDown() { if(frame == 1) { setImage(run0r); frame = 1; return; } frame ++; } } Thats my cat's whole thing. please help D: Im new to this greenfoot thing and i need this for class.
SlayGirlSlay SlayGirlSlay

2022/4/7

#
Dan posts please respond im a fan
Super_Hippo Super_Hippo

2022/4/7

#
Only animateRight resets frame to 1 from 5. The others do not. If for example frame is 4 and now you move left, frame isn’t 1, so it won’t change the image, but frame is increased to 5, then 6 and so on and at this point, animateRight can’t bring it back to 1 either. It will just increase forever.
SlayGirlSlay SlayGirlSlay

2022/4/8

#
How would I make it animate the animation then?
Super_Hippo Super_Hippo

2022/4/8

#
You could try to change “else if(frame == 5)” to “else” and only have the setImage call in all direction methods except right.
danpost danpost

2022/4/9

#
SlayGirlSlay wrote...
Dan posts please respond im a fan
Moved recently with no internet. Will be back in business soon.
SlayGirlSlay SlayGirlSlay

2022/4/12

#
No worries!
You need to login to post a reply.