我试图每秒生成一个精灵或对象,但发生的情况是精灵每秒只渲染不到一秒
public class Player {
private Sprite playerSpr,enemy,enemy1;
public Vector2 position,size;
public Rectangle bounds;
private SpriteBatch batch;
private float deltaTime;
private float timer,elapsedTime;
private ArrayList<Sprite> enemies;
private Iterator<Sprite> enemyIterator;
public void create(){
position=new Vector2(200,910);
size=new Vector2(82,80);
batch=new SpriteBatch();
timer=0;
playerSpr=new Sprite(new Texture(Gdx.files.internal("spr_player.png")));
enemy=new Sprite(new Texture(Gdx.files.internal("spr_player.png")));
enemy1=new Sprite(new Texture(Gdx.files.internal("spr_player.png")));
bounds=new Rectangle(position.x,position.y,size.x,size.y);
enemies=new ArrayList<Sprite>();
enemies.add(playerSpr);
enemies.add(enemy);
}
public void update(){
deltaTime=Gdx.graphics.getDeltaTime();
enemyIterator=enemies.iterator();
timer+=1*deltaTime;
elapsedTime+=1*deltaTime;
playerSpr.setPosition(position.x,position.y);
playerSpr.setSize(size.x,size.y);
bounds.set(position.x,position.y,size.x,size.y);
}
public void movement(){
if(position.y<=910){
position.y-=600*deltaTime;
}
}
/* wan't to draw the next sprite every second, for now I only have to stored in the iterator */
public void draw(){
if(timer>=1){
Sprite cur=enemyIterator.next();
batch.begin();
cur.draw(batch);
batch.end();timer=0;
}
只有 playerpr 的渲染时间少于每秒,我知道是因为计时器每秒都在重置,但是你如何生成或绘制下一个?