我正在使用以下方式更改我的着色器TimerTask
:
public java.util.Timer ExplodeTimerTask = new Timer();
ExplodeTimerTask.schedule(new TimerTask() {
@Override
public void run(){
sprite_explosion.setRegion(textureAtlasExplosion.findRegion("spacesepxl0047"));
exploded = true;
game_upper_screen.TurnToSepiaForContrast();
}
}, 0);
public void TurnToSepiaForContrast(){
this.batch.setShader(shader_finish);
}
50% 的时间着色器被正确激活,否则它会失败并出现以下错误:
exploded one: oneException in thread "Timer-0"
java.lang.RuntimeException: No OpenGL context found in the current thread.
at org.lwjgl.opengl.GLContext.getCapabilities(GLContext.java:124)
at org.lwjgl.opengl.GL11.glBindTexture(GL11.java:651)
at com.badlogic.gdx.backends.lwjgl.LwjglGL20.glBindTexture(LwjglGL20.java:67)
at com.badlogic.gdx.graphics.GLTexture.bind(GLTexture.java:77)
at com.badlogic.gdx.graphics.g2d.SpriteBatch.flush(SpriteBatch.java:955)
at com.badlogic.gdx.graphics.g2d.SpriteBatch.setShader(SpriteBatch.java:1056)
at com.cryotrax.game._ex01MyGame.TurnToSepiaForContrast(_ex01MyGame.java:474)
at com.cryotrax.game.ex01MyGameMain$2.run(ex011MyGameMain.java:1292)
at java.util.TimerThread.mainLoop(Unknown Source)
at java.util.TimerThread.run(Unknown Source)
我只在我的桌面上看到这个,而不是在移动设备上。可能是什么问题?有没有另一种方法可以异步这些调用,这样我就不会收到错误?
如果我不使用异步方法,着色器始终正确设置,但我会得到一些 FPS 下降,我不希望这样。 (我正在使用与帧速率无关的运动。)