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.