我有这个(工作正常):
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"));
我尝试了一下(无论如何都不起作用):
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));
}
出了什么问题?我该如何做才能使这项工作正常进行,同时保持代码的简单性和通用性? 非常感谢!
最佳答案
也许您忘记了.png?
for (int i = 0; i < 4; i++)
{
fileName = String.format("Bubble%1d.png", i+1);
bubble[i] = new Texture(Gdx.files.internal(fileName));
}
关于java - Java 中的纹理数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19653669/