2017-06-15 13 views
1

私はテキストを含むカードを動的に生成する必要のあるゲームに取り組んでいます。これを達成するために、ジェネリックカードの背景といくつかのテキストをフレームバッファにレンダリングしようとしており、スプライトとして使用するためにこれからTextureRegionを作成します。 This is the sprite that is returnedThis is what comes out of the PixMap screenshotTextureRegionへのLibGDX FrameBufferが不正なスプライトをレンダリングしています

上記大、カラフルな画像は、以下の関数によって返されたスプライトは次のようになります。

私の現在の試みは、いくつかのではなく...予期しない結果が作成されます。レンダリングされるイメージは、実際には、テクスチャアトラスがスプライトをロードしているフルスプライトシートです。

2番目の画像(期待される結果)は、pixmapから関数の最後に向かって生成されたPNGスクリーンショットの内容です。

fboRegion.flip()のパラメータを変更すると結果のスプライトに影響するため、関数で生成されたTextureRegionが使用されていることが確認できます。

private Sprite generateCard(String text, TextureAtlas atlas){ 
    //Create and configure font 
    BitmapFont font = new BitmapFont(); 
    font.setColor(Color.RED); 

    //Create a SpriteBatch (Temporary, need to pass this in later) 
    SpriteBatch sb = new SpriteBatch(); 

    //Create sprite from texture atlas 
    Sprite sprite = atlas.createSprite("back", 3); 

    //Create FrameBuffer 
    FrameBuffer fbo = new FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false); 
    //Extract Texture from FrameBuffer 
    TextureRegion fboRegion = new TextureRegion(fbo.getColorBufferTexture()); 
    //Flip the TextureRegion 
    fboRegion.flip(false, true); 

    //Begin using the FrameBuffer (disable drawing to the screen?) 
    fbo.begin(); 
    //Clear the FrameBuffer with transparent black 
    Gdx.gl.glClearColor(0f, 0f, 0f, 0f); 
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); 

    sb.begin(); 
    //Draw card background 
    sb.draw(sprite, 0,0, sprite.getWidth(), sprite.getHeight()); 
    //Draw card text 
    font.draw(sb, text, 20, 100); 

    sb.end(); 

    //Take "Screenshot" of the FrameBuffer 
    Pixmap pm = ScreenUtils.getFrameBufferPixmap(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); 
    PixmapIO.writePNG(new FileHandle("screenshot.png"), pm); 

    fbo.end(); 

    sb.dispose(); 
    fbo.dispose(); 

    return new Sprite(fboRegion); 
} 

誰かが何か提案があれば、私は非常に助けていただければ幸いです。私は何かが間違った順序で起きているように感じますが、FrameBufferがレンダリングしているイメージがどこにあるのか、返されたスプライトが間違ったイメージを持っているのにFrameBufferをPNGにダンプしているのを見ることができません。正しいイメージを与えます。

答えて

0

余分な実験をした結果、上記のコードが意図した通りに機能していることが分かりました。私はスプライトの寸法と位置を取っているが、別のテクスチャをレンダリングしている他のコードに問題を追跡することができました(したがって、テクスチャ領域を変更したときに反転します)。

私の質問をチェックアウトした人に感謝します。

関連する問題