Your code worked PERFECTLY, but I feel like I'm not sure about what each line in test() does.
Could you give me info on each line, or a summary if that is too much?
Thanks.
I also added the image list you wanted.
import greenfoot.*;
public class Score extends Actor
{
GreenfootImage image1;
GreenfootImage image2;
GreenfootImage image3;
GreenfootImage image4;
GreenfootImage image5;
GreenfootImage image6;
GreenfootImage image7;
GreenfootImage image8;
GreenfootImage image9;
GreenfootImage image0;
public Score(){
image1= new GreenfootImage("1.png");
image2= new GreenfootImage("2.png");
image3= new GreenfootImage("3.png");
image4= new GreenfootImage("4.png");
image5= new GreenfootImage("5.png");
image6= new GreenfootImage("6.png");
image7= new GreenfootImage("8.png");
image8= new GreenfootImage("8.png");
image9= new GreenfootImage("9.png");
image0= new GreenfootImage("0.png");
}
public void act()
{
test();
}
public void test(){
GreenfootImage[] digitImage= {image1,image2,image3,image4,image5,image6,image7,image8,image9,image0};
String numberString = ""+Fighter.score;
int digitCount = numberString.length();
GreenfootImage[] digitImages = new GreenfootImage[digitCount];
int textImageWidth = 0;
for (int i=0; i<digitCount; i++)
{
digitImage[i] = new GreenfootImage(""+numberString.charAt(i)+".png");
textImageWidth += digitImage[i].getWidth();
}
GreenfootImage textImage = new GreenfootImage(textImageWidth, digitImage[0].getHeight());
int drawPosition = 0;
for (int i=0; i<digitImage.length; i++)
{
textImage.drawImage(digitImage[i], drawPosition, 0);
drawPosition += digitImage[i].getWidth();
}
setImage(textImage);
}
}
