我想改变我有什么形象,根据随机整数值,但是,日食说,兰特整数需要一个身体。
我已经尝试过这样做
int rand = random.nextInt(4);
但也不能正常工作。任何帮助将不胜感激。
public class GrassTile extends Tile {
Random random = new Random();
static BufferedImage texture;
int rand;
rand = random.nextInt(4);
if (rand == 0) {
texture = Assets.grass0;
} else if(rand == 1) {
texture = Assets.grass1;
} else if(rand == 2) {
texture = Assets.grass2;
} else if(rand == 3) {
texture = Assets.grass3;
}
public GrassTile(int id) {
super(texture, id);
}
}
谢谢,Javdev
你的代码是不是要初始化纹理至极逻辑与非静态字段静态字段
移除纹理static关键字,把初始化在构造函数