我有这个(工作正常):
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));
}
怎么了?在保持代码的简单性和通用性的同时,我能做些什么来完成这项工作?非常感谢!