如何从 imputProcessor 类绘制纹理?LibGDX.



我尝试使用LibGDX的InputProcessor类绘制东西。但是什么都没有画!我可以从任何其他地方绘制纹理而不是在 LibGDX 中渲染 () 类吗?

是的,如果我在 render () 类中绘制它就可以了,但是我可以从其他地方绘制吗,比如输入处理器触摸拖动?

这是我的代码

public class mm_imput implements InputProcessor {
 SpriteBatch batch=new SpriteBatch();
 Texture pixel=new Texture("something.png");
   @Override
   public boolean touchDragged (int x, int y, int pointer) {
      drawSomething();
   }
   void drawSomething() {
        batch.begin();
        batch.draw(pixel, 100, 100, 100, 100);
        batch.end();
    }

}

每次我拖动鼠标时,它都应该显示一些东西。如何实现这一点?

批处理

必须位于屏幕类的 Render 方法中。

在此链接中,您将看到我在说什么:https://github.com/littletinman/Hype/blob/master/Hype/core/src/com/philiproyer/hype/screens/Details.java

我有一个主屏幕类,带有 Render 方法。我正在实现输入处理器接口。

我建议让 Render 方法处于触摸关闭的条件。

public void render(float delta) {
    Gdx.gl.glClearColor( 0, 0, 0, 1); // Clear the screen with a solid color
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    if(isTouching == true) { // check for touching
      batch.begin();
        batch.draw(pixel, 100, 100, 100, 100);
      batch.end();
    }
}

然后,在 touchDown 方法中添加类似以下内容的内容

public boolean touchDown(int screenX, int screenY, int pointer, int button) {
    isTouching = true; // Set boolean to true
    return false;
}

要确保在停止触摸时重置它,请在 touchUp 方法中执行以下操作

public boolean touchUp(int screenX, int screenY, int pointer, int button) {
    isTouching = false; // Set boolean to false
    return false;
}

如果有什么不太清楚的地方,请告诉我。祝你好运!

最新更新