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

2016/12/4

problem with array need help

1
2
jrod159 jrod159

2016/12/4

#
what would i have to do to put 2 images in the string i tried doing this but it doesnt work
public Invaders(String b)
    {
        setImage("Marine.PNG", "spearman.png");
    }
Super_Hippo Super_Hippo

2016/12/4

#
The 'setImage' method sets an image to an (Actor) object. What do you want to achieve with two images?
jrod159 jrod159

2016/12/4

#
i want to have 3 rows of different images on the screen and all of them belonging to the actor class
Super_Hippo Super_Hippo

2016/12/4

#
You could try this:
private static GreenfootImage[] images =
{
    new GreenfootImage("Marine.png"),
    new GreenfootImage("spearman.png"),
    new GreenfootImage("otherImage.png")
};

public Invaders(int type)
{
    setImage([images[type]);
}
Then you need to use 'addObject(new Invader(number)...' with 'number' being 0 for the first row, 1 for the second and 2 for the third.
You need to login to post a reply.
1
2