簡體   English   中英

使用Sprite.draw(batch)LibGDX時未繪制Sprite類

[英]Sprite class not drawn when using Sprite.draw(batch) LibGDX

我試圖顯示使用Sprite類縮放的紋理。 問題是當我嘗試運行代碼時。 我可以在Android 4.1中顯示紋理,但是當我在另一個Android中運行相同的程序(例如2.2、2.3.6)時,不會顯示Sprite。 這是我的代碼。

public void render() {
    // TODO Auto-generated method stub
    Gdx.gl10.glClearColor(1, 0.4f, 0.3f, 1);
    Gdx.gl10.glClear(GL10.GL_COLOR_BUFFER_BIT);
    if(estadojuego==0){
        batch.begin();
        sboton1.draw(batch);
        sboton2.draw(batch);
        batch.end();
        if(Gdx.input.isTouched()){
            System.out.println("x"+Gdx.input.getX());
            System.out.println("y"+Gdx.input.getY());
            if(Gdx.input.getY()<(altura-posicion1.y) && Gdx.input.getY()>(altura-(posicion1.y+posicion1.height))){
                if(Gdx.input.getX()<(posicion1.x+posicion1.width) && Gdx.input.getX()>posicion1.x){
                    //estadojuego=1;
                    System.out.println("boton1");
                }
                if(Gdx.input.getX()<(posicion2.x+posicion2.width) && Gdx.input.getX()>posicion2.x){
                    estadojuego=2;
                }
            }
        }
    }
    if(estadojuego==2){
        batch.begin();
        sboton3.draw(batch);
        batch.end();
        if(Gdx.input.isTouched()){
            if(Gdx.input.getY()<(altura-posicion3.y) && Gdx.input.getY()>(altura-(posicion3.y+posicion3.height))){
                if(Gdx.input.getX()<(posicion3.x+posicion3.width) && Gdx.input.getX()>posicion3.x){
                    estadojuego=0;
                }
            }
        }
    }
}

非常感謝,抱歉我的英語不好。

似乎您沒有為批次設置Matrix4

用這個 :

private Matrix4 Projection;

create()中

Projection = new Matrix4().setToOrtho2D(0, 0, (float) Gdx.graphics.getWidth(), (float) Gdx.graphics.getHeight());

在batch.begin之前渲染()();

batch.setProjectionMatrix(Projection);

希望對您有所幫助。

暫無
暫無

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

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