我最近开始使用 libgdx,需要在屏幕上逐个像素地绘制,想知道最有效/优化的方法是什么,这是我目前正在做的:
package com.mygdx.game;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class MyGdxGame extends ApplicationAdapter {
private SpriteBatch batch;
private Pixmap pixmap;
private Texture tex;
private final int screenWidth = 1280;
private final int screenHeight = 720;
@Override
public void create() {
batch = new SpriteBatch();
pixmap = new Pixmap(
screenWidth,
screenHeight,
Format.RGBA8888
);
tex = new Texture(pixmap);
}
@Override
public void render() {
for (int x = 0; x < screenWidth; x++) {
for (int y = 0; y < screenHeight; y++) {
pixmap.drawPixel(x, y, 0xFF0000FF);
}
}
System.out.println(Gdx.graphics.getFramesPerSecond());
tex.draw(pixmap, 0, 0);
batch.begin();
batch.draw(tex, 0, 0); //draw pixmap texture
batch.end();
}
}
这是我目前在我的整个项目上所做的,但我想这比共享整个代码更实用。