Hi, I needed some help with my new game... I am trying to change the image when the character moves up and down, and I am having trouble creating the variable.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class PlayerChar here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class PlayerChar extends Actor
{
/**
* Act - do whatever the PlayerChar wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
charImage++;
public void act()
{
if (Greenfoot.isKeyDown("up"))
{
int x = getX();
int y = getY();
int ny = getY()-1;
setLocation(x,ny) ;
GreenfootImage charImage = new GreenfootImage("IMG_1191.PNG");
}
if (Greenfoot.isKeyDown("down"))
{
int x = getX();
int y = getY();
int ny = getY()+1;
setLocation(x,ny) ;
GreenfootImage charImage = new GreenfootImage("IMG_1190.PNG");
}
if (Greenfoot.isKeyDown("left"))
{
int x = getX();
int y = getY();
int ny = getX()-1;
setLocation(ny,y) ;
}
if (Greenfoot.isKeyDown("right"))
{
int x = getX();
int y = getY();
int ny = getX()+1;
setLocation(ny,y) ;
}
setImage(charImage);
}
}


