I have a coin class which takes in an integer numOfCoinsand an enum LayoutType, which can be linear or curved. A linear layout displays the coins in a straight line one after the other - we'll work with this since the method is small and straight forward.
My constructor looks like this:
public Coin(float xPos, float yPos, int numOfCoins, LayoutType layout) {
setType(ObjectType.COIN);
coinList = new ArrayList<Coin>(); // arraylist of coins
setPos(xPos, yPos); // set starting position of coin(s)
if (layout == LayoutType.LINEAR)) {
linearLayout(); // display coins in a straight line
} else if (layout == LayoutType.CURVE{
curveLayout();
}
}
And my linearLayout() method looks like this
public void linearLayout() {
//draw numOfCoins amount of coins in a straight line
for (int i = 0; i < numOfCoins; i++) {
Coin coin = new Coin(xPos, yPos);
coinList.add(coin);
xPos += 50; // place coins 50 pixels apart
}
}
I have a working animation class and a spritesheet for the coins - however, the way I have modelled my coins is in such a way that 1 coin object can contain numOfCoins amount of coins, so I can't just directly call the animation in the draw method.
The class' draw() method is in an abstract class GameObject which Coin extends. It looks like this:
public void draw(SpriteBatch batch) {
// if the object is a coin iterate through the list of coins
// and draw the sprites, if it isn't a coin, simply draw the objects sprite
if (type == ObjectType.COIN) {
for (Coin coin : getCoinList()) {
coin.getCoinList().draw(batch);
}
} else {
sprite.draw(batch);
}
}
This draw() method is called in World.render().
How would I create an animation using my Animatorclass for each coin if I have 6 coins in a straight line for instance? I can't seem to find a way. Highly grateful for any help, thanks.
draw()is overridden for Coin class, why does it checkif (type == ObjectType.COIN)? It's hard to say how your Animator class should interact with Coin as you didn't give any details of the Animator class. \$\endgroup\$