我写了一些简单的桌面程序来绘制一些精灵:
SpriteBatch batch = new SpriteBatch();
Sprite[] sprites;
public MainScreen() {
Gdx.gl.glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
sprites = new Sprite[128];
Texture texture = new Texture(Gdx.files.internal("textures/gun.png"));
for(int i = 0; i < sprites.length; i++) {
sprites[i] = new Sprite(texture);
sprites[i].setPosition((float)Math.random()*1280, (float)Math.random()*720);
}
}
@Override
public void render(float delta) {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
for(Sprite s : sprites) s.draw(batch);
batch.end();
}
效果很好,处理器加载1-4%,但如果我增加精灵数量高于128,则负载增加到25%。为什么会这样,怎么办?