我创建了Array<InputProcessor>();
,我添加了stage
和this
(我的类实现了InputProcessor
:
public MyClass implements Screen, InputProcessor {
private Stage stage;
.....
private InputMultiplexer inputMultiplexer;
private Array<InputProcessor> arrayProcessor = new Array<InputProcessor>();
@Override
public void show() {
.....
arrayProcessor.add(this);
arrayProcessor.add(stage);
inputMultiplexer = new InputMultiplexer();
inputMultiplexer.setProcessors(arrayProcessor);
Gdx.input.setInputProcessor(inputMultiplexer);
}
.....
}
我首先调用了touchUp
方法,删除了inputProcessor:
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
isTouchUp = true;
return false;
}
在render
方法中:
@Override
public void render(float delta) {
.....
if(isTouchUp) {
arrayProcessor.removeValue(this, true);
isTouchUp = false;
}
}
其次,我从touchUp
actor的监听器调用了Image
方法,该监听器添加了inputProcessor:
listener = new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
return true;
}
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
arrayProcessor.clear();
arrayProcessor.add(MyClass.this);
arrayProcessor.add(stage);
}
}
image.addListener(listener);
我重复删除和添加inputProcessor 3次。
到现在为止一切正常。
但是何时和我处理MyClass
屏幕并设置新的Screen
,
((Game) Gdx.app.getApplicationListener()).dispose();
((Game) Gdx.app.getApplicationListener()).setScreen(new TestScreen());
MyClass
处置了3次。
@Override
public void dispose() {
System.out.println("MyClass diposed");
stage.dispose();
.....
}
然后输出显示为Exception
:
MyClass diposed
MyClass diposed
MyClass diposed
Exception in thread "LWJGL Application" java.lang.IllegalArgumentException: buffer not allocated with newUnsafeByteBuffer or already disposed
我觉得我的代码中有一些微不足道的错误,我不知道为什么:),我试图找到它但无济于事。
任何人都可以帮助我?