Okay, I'm pretty sure I'm missing something here, but this is my problem: I have an abstract parent class, in which I have a defined(not abstract) method, which is the same for all subclasses. Problem is, it needs to access the attributes of the subclass object it is called with. But it doesn't do that and instead uses the (non-defined) attributes of the abstract class.
I feel like there's an easy solution to that, but I can't think of it.
Code parent:
public abstract class Background
{
private boolean fadeTriggered;
private int flagFade;
public void checkFade(Background fadeFrom, Background fadeInto, SpriteBatch batch, ParallaxBackground parallaxBackground) {
//Clean up
if (fadeFrom.getFadeTriggered()) {
fadeFrom.setFadeTriggered(false);
if (fadeFrom.getFlagFade() > 0) {
fadeFrom.setFlagFade(0);
}
}
//Fade
if (!fadeTriggered) {
fadeTriggered = true;
flagFade = 1000;
}
if (flagFade > 0) {
parallaxBackground.draw(batch, this.getID(), 1);
parallaxBackground.draw(batch, fadeInto.getID(), flagFade * .001f);
flagFade--;
} else {
parallaxBackground.draw(batch, this.getID(), 1f);
}
}
}
Code Child:
public class BackgroundSnow extends Background {
private ArrayList<ParallaxTexture> textures;
private int textureCount;
private final String biomeName = "Default";
private final int id = 1;
protected boolean fadeTriggered = false;
protected int flagFade = 0;
public BackgroundSnow() {
int i = 1;
while (true) {
if (!Gdx.files.internal("backgrounds/parallax/" + biomeName + "/img" + i + ".png").exists()) {
this.textureCount = i - 1;
break;
}
i++;
}
Printer.debugPrintToConsole(ParallaxBackground.class, "Parallax Backgrounds found: " + Integer.toString(textureCount));
textures = new ArrayList<>();
for (int j = 1; j < textureCount + 1; j++) {
textures.add(new ParallaxTexture(j, biomeName));
}
}
}
and then you call checkFade with some instance of the childclass