This site requires JavaScript, please enable it in your browser!
Greenfoot back
davemib123
davemib123 wrote ...

2014/8/24

stopping and then continuing array of images

1
2
danpost danpost

2014/8/25

#
Ok. It would probably be best to combine your image array into a double array. You can do that this way:
public static final GreenfootImage[][] conversations = new GreenfootImage[][]
{
    new GreenfootImage[7],
    new GreenfootImage[3]
};
static
{
    // code to fill image arrays    
}
Then you can have an instance 'int' field to track which animation is running and another one to track the image within that animation:
private int animationIndex, imageIndex;
This should give you the ability to easily change which animation is running (basically, just change the value of the 'animationIndex' field).
danpost danpost

2014/8/25

#
The code to fill the arrays would be like this:
for (int anim=0; anim < conversations.length; anim++)
{
    for (int img = 0; img < conversations[anim].length; img++)
    {
        String filename = "Text/Conversation/"+(anim+1)+"/"+(img+1)+".gif";
        conversations[anim][img] = new GreenfootImage(filename);
    }
}
davemib123 davemib123

2014/8/25

#
so this part:
static  
{  
    // code to fill image arrays      
}
should be:
static  
    {  
        for (int i = 0; i < Conversation1.length; i++)
        {
            this.fileNameDirectory = "Text/Conversation1/";
            fileName = fileNameDirectory + (i+1) + fileNameSuffix;
            palletTownSign1[i] = new GreenfootImage(fileName);
        }
    } 
danpost danpost

2014/8/25

#
Look at my last post.
Super_Hippo Super_Hippo

2014/8/25

#
danpost wrote...
However, you only initialize the array. You do not ever put any actual images in the arrays.
Didn't he put the images which he named 'Text/Conversation1/X.gif' (with X as the number) in the array with this code?
        for (int i = 0; i < Conversation1.length; i++)
        {
            this.fileNameDirectory = "Text/Conversation1/";
            fileName = fileNameDirectory + (i+1) + fileNameSuffix;
            Conversation1[i] = new GreenfootImage(fileName);
        }
danpost wrote...
@Super_Hippo, the field you are trying to find is probably declared in the Tile class (the superclass of the class this code is in).
Yes, he said that. But in the constructor of 'Text' he also initializes it to 0. But as I said, this actually shouldn't matter. If I didn't misunderstand the problem, then both conversations work as they should if he creates them manually, but if he codes it to add the Text in the world
getWorld().addObject(new Text("Conversation2"), getWidth() / 2, 309);
then the second conversation starts with the last picture and stays there. Btw, you could change
        if (selection == "Conversation1")
        {
            if (animationCounter > Conversation1.length - 6)
            {
                animationCounter = Conversation1.length - 6;
            }      
            setImage (Conversation1[animationCounter]);
        }
to
        if (selection == "Conversation1")
        {
            if (animationCounter < Conversation1.length - 7)
            {
                setImage (Conversation1[animationCounter]);
            }
        }
This way it doesn't always creates a new picture if it is already at the last place. Doesn't help you with your problem though, I guess...
danpost danpost

2014/8/25

#
Super_Hippo wrote...
< Quote Omitted > Didn't he put the images which he named 'Text/Conversation1/X.gif' (with X as the number) in the array with this code? < Code Omitted >
I guess so. However, that post was not present when I was writing that which you quoted.
davemib123 davemib123

2014/8/27

#
took longer than expected but its done :). Many thanks danpost and Super_Hippo
You need to login to post a reply.
1
2