So basically, I'm trying to make a simple "Create a character" screen like this
The code for an arrow, in this case for now the left arrow for the hair is this:
and the code for the character who's supposed to be changing image as hairstyle value changes is this:
So my problem is that, I can't seem to get the character to change image when an arrow is pressed, so far I've only coded for the two hair arrows, the left and the right-- they have nearly identical codes, with the only difference in the method that they execute (lefthair and righthair) who's values are pretty much just opposite.
I have put the images needed in the greenfoot folder also. I think my mistake is in how I declared the variables equating them to 1? To be honest, I have no idea what I'm doing and I'm new to this so, all help is appreciated. Thank you!
The code for an arrow, in this case for now the left arrow for the hair is this:
import greenfoot.*;
/**
* Write a description of class LeftArrowH here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class LeftArrowH extends HairArrow
{
private boolean onThis = false;
public static int hairstyle = 1;
/**
* Act - do whatever the LeftArrowH wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
// Add your action code here.
if(Greenfoot.mouseMoved(null)){
onThis = Greenfoot.mouseMoved(this);
}
if(onThis)
{
setImage("arrow_left_hover.png");
GreenfootImage image = getImage();
image.scale(100, 75);
setImage(image);
}
else {
setImage("arrow_left_null.png");
GreenfootImage image = getImage();
image.scale(100, 75);
setImage(image);
}
if (Greenfoot.mouseClicked(this)) {
setImage("arrow_left_click.png");
GreenfootImage image = getImage();
image.scale(100, 75);
setImage(image);
lefthair();
}
}
public LeftArrowH()
{
GreenfootImage image = getImage();
image.scale(100, 75);
setImage(image);
}
public void lefthair()
{
if (hairstyle == 1)
{hairstyle = 3;}
if (hairstyle == 2)
{hairstyle = 1;}
if (hairstyle == 3)
{hairstyle = 2;}
}
}
import greenfoot.*;
/**
* Write a description of class CreateCharacter here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class CreateCharacter extends CreateClass
{
public static int hairstyle = 1;
public static int batch = 1;
public static int skin = 1;
/**
* Act - do whatever the Character wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
// Add your action code here.
if (hairstyle == 1 && batch == 1 && skin == 1)
{
setImage("h1b1s1.png");
}
if (hairstyle == 2 && batch == 1 && skin == 1)
{
setImage("h2b1s1.png");
}
if (hairstyle == 3 && batch == 1 && skin == 1)
{
setImage("h3b1s1.png");
}
}
}

