アイテム (Sword1) をランダムな場所に生成したいと考えています。スポーンすると、まず1つしか作成されず、ランダムにどこにでも移動します。オブジェクトを作成して配列する必要がありますか? どのように?
public class Sword1 {
public static TextureRegion sprite;
public static int x;
public static int y;
public static int size;
public static boolean created;
public Sword1(){
created=true;
Random r = new Random();
x = (r.nextInt(5)+1)*GameRender.tilesize;
y = (r.nextInt(5)+1)*GameRender.tilesize;
size = GameRender.tilesize;
sprite = AssetLoader.s1;
createMe();
}
public static void createMe() {
GameRender.batch.draw(sprite, x, y, size, size);
}
}
バッチでレンダリングします:
while(number<4){
number++;
Items.createSwords();
}
また、さらにアイテムがある場合にすべてのアイテムを保持するアイテムクラスを使用しようとしました
public class Items {
public Items(){}
public static void createSwords() {
Object sword = (Sword1) new Sword1();
}
}