gpt4 book ai didi

java - 如何显示转动大像素图过程的指示器?

转载 作者:行者123 更新时间:2023-11-30 10:02:55 26 4
gpt4 key购买 nike

需要在我的游戏中旋转大像素图(来自画廊)。为此,我使用以下代码。

例如:

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();
}

问题是大图转得太长了。来自这个卡住程序。

我尝试在单独的线程中执行此操作,但出现黑屏。

我尝试显示转弯指示器,但它是在转弯过程之后才绘制的。

现在我正在尝试减少像素图,但在弱设备上仍然卡住。

最佳答案

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

因此,在 rotate() 中获取 for 循环之后的所有代码,并将其包装在 Runnable 中。调用 Gdx.app.postRunnable()

关于java - 如何显示转动大像素图过程的指示器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56440702/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com