我正在尝试根据随机整数的值更改我拥有的图像,但是,eclipse 表示 rand 整数需要一个主体。
我已经尝试过
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);
}
}
谢谢,JavaDev
三国纷争
浮云间
随时随地看视频慕课网APP
相关分类