簡體   English   中英

如何從imputProcessor類繪制紋理? LibGDX

[英]How to draw texture from imputProcessor class? LibGDX

我嘗試使用LibGDX的InputProcessor類繪圖。 但是什么也沒畫! 我可以從其他任何地方繪制紋理,而不是在LibGDX中繪制render()類嗎?

是的,如果我繪制render()類,就可以繪制,但是可以從其他地方繪制,例如InputProcessor touchDragged嗎?

這是我的代碼

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

}

每當我拖動鼠標時,它都應該顯示一些東西。

您的批處理必須位於Screen類的Render方法中。

在此鏈接上,您將看到我在說什么: https : //github.com/littletinman/Hype/blob/master/Hype/core/src/com/philiproyer/hype/screens/Details.java

我有一個主屏幕類,帶有一個Render方法。 我正在實現InputProcessor接口。

我建議在觸摸下降的情況下使用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;
}

讓我知道是否有任何不清楚的地方。 祝你好運!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM