So this is my code:
This code is for animating a character, but whenever I set my timer To anything other than 1 or 2, weird stuff begins to happen, such as the animation only working a couple of frames or not animating at all. Please help.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Player here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Player extends Actor
{
/**
* Act - do whatever the Player wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
private static GreenfootImage walk1 = new GreenfootImage("Walk1.png");
private static GreenfootImage walk2 = new GreenfootImage("Walk2.png");
private static GreenfootImage walk3 = new GreenfootImage("Walk3.png");
private static GreenfootImage walk4 = new GreenfootImage("Walk4.png");
private static GreenfootImage walk5 = new GreenfootImage("Walk5.png");
private static GreenfootImage walk6 = new GreenfootImage("Walk6.png");
private static GreenfootImage walk7 = new GreenfootImage("Walk7.png");
private static GreenfootImage walk8 = new GreenfootImage("Walk8.png");
private static GreenfootImage walk9 = new GreenfootImage("Walk9.png");
private static int frame = 1;
private static int timer = 1;
public void act()
{
move();
}
public void move(){
if(Greenfoot.isKeyDown("d")){
timer = timer - 1;
frame++;
if(timer == 0){
switch(frame){
case 1: this.setImage(walk1);
break;
case 2: this.setImage(walk2);
break;
case 3: this.setImage(walk3);
break;
case 4: this.setImage(walk4);
break;
case 5: this.setImage(walk5);
break;
case 6: this.setImage(walk6);
break;
case 7: this.setImage(walk7);
break;
case 8: this.setImage(walk8);
break;
case 9: this.setImage(walk9);
break;
case 10: this.setImage(walk1);
frame = 2;
break;
}
timer = 2;
}
}
}
}

