I would like to insert random enemies in the map in different positions. It's possible?
This is how i load image of enemy: Enemy.java:
public class Enemy {
public Array<Sprite> enemy = new Array<Sprite>(2);
public void nemici() {
Sprite mysterio;
Sprite boss;
enemy.add(mysterio = new Sprite(new Texture("mysterio.png")));
enemy.add(boss = new Sprite(new Texture("boss.png")));
}
}
And this is how i draw with my level1.java:
public class Level1 implements Screen{
private Texture BackgroundLevel1;
NameGame game;
Sprite card;
private Enemy enemies = new Enemy();
public Level1 (NameGame game){
this.game = game;
enemies.nemici();
card = enemies.enemy.random();
BackgroundLevel1 = new Texture("BackgroundLevel1.png");
}
@Override
public void show() {
}
@Override
public void render(float f) {
Gdx.gl.glClearColor(0, 0, 0, 0);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
game.batch.begin();
//Background
game.batch.draw(BackgroundLevel1, 0, 0, NameGame.WIDTH, NameGame.HEIGHT);
game.batch.draw(card,200,0,100,100); //Example
game.batch.end();
}
public Level1 (NameGame game)
you create a collection of positions where an enemy could spawn, then randomly pick one of those positions. Then again, that may make sense, or that may not make sense, depending on your game. \$\endgroup\$