I'm creating a game with a tank, and so far I have at least three animated effects in mind: muzzle blast, exhaust and the shell's impact.
Now obviously these effects won't do much, they'll go through a couple of images then remove themselves. I wanted to create an Effects class that would do just that, with a MuzzleBlast, Exhaust, and Impact subclass. I wanted to load images in the subclass into a GreenfootImage array and send it to the Effects class.
This was my first attempt at it:
Effects:
MuzzleBlast:
MuzzleBlast won't compile: "cannot reference imageArray before supertype constructor has been called"
Am I making a simple mistake here or this cannot be done through the constructor and I'll have to call another function after super() to send the images?
private boolean moving;
private int timerDone;
private int timer = 0;
private GreenfootImage[] imageArray;
public Effects(int rotation, boolean _moving, GreenfootImage[] _imageArray)
{
setRotation(rotation);
moving = _moving;
imageArray = _imageArray;
timerDone = imageArray.length*10;
}
public void act()
{
//animation code here
} private GreenfootImage[] imageArray = {
new GreenfootImage("fire1.png"),
new GreenfootImage("fire2.png"),
new GreenfootImage("fire3.png"),
new GreenfootImage("fire4.png"),
};
public MuzzleBlast(int rotation, boolean moves)
{
super(rotation, moves, imageArray);
}
