0
public void render(float delta) {
    Gdx.gl.glClearColor(0, 0, 0.2f, 1);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    stage.act(delta);

    batch.setProjectionMatrix(camera.combined);
    batch.begin();
    if (lifeCount > 0) {
        /* 
        When stage.draw is called here, it only displays the exit button.
        The game still operates, but everything is invisible.
        If I leave the game on, the game over screen is shown,
        */
        stage.draw();
        text.setColor(1.0f, 1.0f, 1.0f, 1.0f);
        text.draw(batch, score + scoreCount, 25, 100);
        text.draw(batch, lives + lifeCount, 25, 120);
        text.draw(batch, speed + raindropSpeed, 25, 80);
        batch.draw(bucketTexture, bucket.x, bucket.y);
        for (Rectangle clearDrop : clearDrops) {
            batch.draw(clearDropTexture, clearDrop.x, clearDrop.y);
        }
        for (Rectangle healthDrop : healthDrops) {
            batch.draw(healthDropTexture, healthDrop.x, healthDrop.y);
            /* 
             If I place stage.draw here, health drops are invisible.
             This also happens if I place it in the raindrop for-loop and the 
             cleardrop for-loop
            */ 
        }
        for (Rectangle raindrop : raindrops) {
            batch.draw(raindropTexture, raindrop.x, raindrop.y);
        }
        /*
         If I place stage.draw here, the bucket, score, life, and speed
         display correctly. The drops are still invisible.
         */
    } else {
        pause();
        raindrops.clear();  
        game.setScreen(new GameOver(game));
    }
    batch.end();

私がやろうとしているのは、GameScreen の右上隅に終了ボタンを配置することですが、ボタンが存在するステージを描画すると問題が発生します (コードのコメントを参照)。

終了ボタンとステージ (resize()) のコードは次のとおりです。

if (stage == null)
        stage = new Stage(width, height, true);
    stage.clear();

    Gdx.input.setInputProcessor(stage);

    TextButtonStyle styleQuit = new TextButtonStyle();
    styleQuit.up = skin.getDrawable("buttonnormal");
    styleQuit.down = skin.getDrawable("buttonpressed");
    styleQuit.font = text;

    quitButton = new TextButton(" ", styleQuit);
    quitButton.setWidth(128);
    quitButton.setHeight(128);
    quitButton.setX(800 - 128);
    quitButton.setY(480 - 100);

    quitButton.addListener(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) {
            Gdx.app.log(RainCatcher.LOG, "Quit Button Pressed");
            game.setScreen(new MainMenu(game));
        }
    });

    stage.addActor(quitButton);

そして残り(show()内)

    atlas = new TextureAtlas("gamebuttons.pack");
    skin = new Skin();
    skin.addRegions(atlas);
    text = new BitmapFont();

落ちる雨粒、バケツ、テキストと一緒にステージをレンダリングできる特別なトリックはありますか? 私の友人と私は困惑しており、どこにも解決策を見つけることができませんでした.

4

2 に答える 2

0

stage.draw() を batch.end() の後または batch.begin() の前に移動

于 2013-08-15T05:41:43.827 に答える
0

私の意見では、これはあなたが取っている正しいアプローチではありません。libgdx でステージを使用している場合は、Scene2d の他のコンポーネントを利用する必要があります。したがって、雨滴と他のゲーム エンティティを別々に描画する (そして作業を複雑にする) のではなく、それらをアクターにして必要な場所にステージに追加し、レンダリングでステージを描画する必要があります。

例えば:

   public class RaindDrop extends Actor {
    TextureRegion region;

    public RaindDrop () {
            region = new TextureRegion(...);
    }

    public void draw (SpriteBatch batch, float parentAlpha) {
            Color color = getColor();
            batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
            batch.draw(...);
    }
  }

他のエンティティについても同様です。それらを初期化してステージに追加します。

詳細を読むための公式wikiは次のとおりです。

https://code.google.com/p/libgdx/wiki/scene2d

于 2013-08-15T06:12:02.787 に答える