有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何显示旋转大型pixmap过程的指示器?

需要在我的游戏中旋转大pixmap(来自图库)。 我使用以下代码来实现这一点

例如:

public class MyGdxGame extends ApplicationAdapter {

private int w = 720, h = 1280;
private Stage stage;
private Image bigImg, button, rotationIndicator;

private Pixmap pixmap0;
private Pixmap pixmap90;
private Texture textureBigImg;
private String buttonPath = "badlogic.jpg", bigImgPath = "DSC_0006.JPG"; //DSC_0006.JPG: 5504x3096

private Thread thread;

@Override
public void create () {
    stage = new Stage(new FillViewport(w, h));

    button = new Image(new Texture(buttonPath));
    textureBigImg = new Texture(bigImgPath);
    bigImg = new Image(textureBigImg);
    rotationIndicator = new Image(new Texture(buttonPath));

    rotationIndicator.setPosition(720-256,0);
    button.setPosition(0,0);
    bigImg.setBounds( 0,256, w, w*3096/5504f);

    pixmap0 = new Pixmap(Gdx.files.internal(bigImgPath));

    thread = new Thread(new Runnable() {
        @Override
        public void run() {
            rotation();
        }
    });

    button.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            stage.addActor(rotationIndicator);

            rotation();                                 //rotationIndicator draw only after the turn process.
            //thread.start();                           //I get a black screen.

        }
    });

    stage.addActor(button);
    stage.addActor(bigImg);
    Gdx.input.setInputProcessor(stage);
}

private void rotation() {
    pixmap90 = new Pixmap(pixmap0.getHeight(), pixmap0.getWidth(), pixmap0.getFormat());

    for (int y = 0, a = 0; y<pixmap0.getWidth(); ++y, ++a) {
        for (int x = 0, b = pixmap0.getHeight(); x<pixmap0.getHeight(); ++x, --b) {
            pixmap90.drawPixel(x, y, pixmap0.getPixel(a, b));
        }
    }

    textureBigImg.dispose();
    textureBigImg = new Texture(pixmap90);
    textureBigImg.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
    bigImg.setDrawable(new TextureRegionDrawable(new TextureRegion(textureBigImg)));
}

@Override
public void render () {
    Gdx.gl.glClearColor(1, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    stage.draw();
}

@Override
public void dispose () {
    pixmap0.dispose();
    pixmap90.dispose();
    textureBigImg.dispose();
}

}

问题是,大局变长了。从这个冻结计划中

我试图用一个单独的线程来做,但我得到了一个黑屏

我试图显示转向指示灯,但它只在转向过程后绘制

现在我正试图减少pixmap,但在较弱的设备上,仍然存在冻结


共 (1) 个答案

  1. # 1 楼答案

    不能创建新的纹理对象或在单独的线程中操作它们,因为它们是OpenGL对象。创建旋转的像素贴图后,rotate()方法应该将runnable发送回GL线程以加载纹理

    因此,在rotate()中获取for循环之后的所有代码,并将其包装在可运行的文件中。打电话Gdx.app.postRunnable()