1

I have this (works fine):

public static Texture bubble1 = new Texture(Gdx.files.internal("Bubble1.png"));
public static Texture bubble2 = new Texture(Gdx.files.internal("Bubble2.png"));
public static Texture bubble3 = new Texture(Gdx.files.internal("Bubble3.png"));
public static Texture bubble4 = new Texture(Gdx.files.internal("Bubble4.png"));

And i try it (do not work in any way):

String fileName;
Texture[] bubble;
bubble = new Texture[4];

for (int i = 0; i < 4; i++){
    fileName = String.format("Bubble%1d", i+1);
    bubble[i] = new Texture(Gdx.files.internal(fileName));
}

What is wrong? What can I do to make this work while maintaining the simplicity and generality of the code? Thank you very much!

1 Answer 1

2

Maybe you forgot .png?

for (int i = 0; i < 4; i++)
{
    fileName = String.format("Bubble%1d.png", i+1);
    bubble[i] = new Texture(Gdx.files.internal(fileName));
}
Sign up to request clarification or add additional context in comments.

2 Comments

Shouldn't it be "Bubble%d.png" or "Bubble%1$d.png"?
It depends on your task.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.