私のデザインのため、NinePatchオブジェクトを取り除きたいが、フレームバッファを使用してテクスチャを初期化し、そのテクスチャをカスタムに適用するオブジェクトLibgdx - フレームバッファのテクスチャを画面にレンダリングするときのサイズが異なる
LibGDXとGLの新機能です。
私は画像をスクリーニングするためにFBOテクスチャを描画するときに問題があるが小さいので、
は、私がここからこのすべての骨格をつかむなぜIDKの:https://stackoverflow.com/a/7632680/401529
マイRenderToTextureクラスは次のとおりです。
public class RenderToTexture {
private float fbScaler = 1f;
private boolean fbEnabled = true;
private FrameBuffer fb = null;
private TextureRegion fbReg = null;
[... more constructors ... ]
/**
*
* @param scale
*/
public RenderToTexture(int width, int height, float scale, boolean hasDepth) {
if(width == -1){
width = (int) (Gdx.graphics.getDisplayMode().width * scale);
}
if(height == -1){
height = (int) (Gdx.graphics.getDisplayMode().height * scale);
}
fb = new FrameBuffer(
Pixmap.Format.RGBA8888,
(int)(width * fbScaler),
(int)(height * fbScaler),
hasDepth
);
fbReg = new TextureRegion(fb.getColorBufferTexture());
fbReg.flip(false,false);
}
public void begin(){
if(fbEnabled) {
fb.begin();
Gdx.gl.glClearColor(0, 0,0,0);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
}
}
public TextureRegion end(){
if(fb != null)
{
fb.end();
return fbReg;
// batch.draw(fboRegion, 0, 0);
}
return null;
}
}
そして、私のutilのクラス:
public class ImageUtils {
public static TextureRegion ninePatchToTextureRegion(NinePatch patch, int width, int height){
return ninePatchToTextureRegion(new NinePatchDrawable(patch), width, height);
}
public static TextureRegion ninePatchToTextureRegion(NinePatchDrawable patch, int width, int height){
RenderToTexture r2t = new RenderToTexture(width, height, 1, false);
SpriteBatch sb = new SpriteBatch();
r2t.begin();
sb.begin();
patch.draw(sb, 0, 0, width, height);
sb.end();
sb.dispose();
return r2t.end();
}
}
そしてiは、スプライトを作成するとき、このutilのクラスを呼び出す:現在の結果は
NinePatchDrawable ninepatchtest = new NinePatchDrawable(
new NinePatch(new Texture(Gdx.files.internal("img/ui/btn-retro-blue.png")), 5, 5, 5, 5)
);
TextureRegion result = ImageUtils.ninePatchToTextureRegion(ninepatchtest, 200, 100);
sprite = new Sprite(result);
(左)とサイズシミュレート所望の結果(右)
EDIT:カメラサイズは、ディスプレイモードのサイズで、画面に貼り付けられます。ズームも移動もありません。
EDIT:この方法は、それを行うための最善の方法ではない場合
Tenfour04 @によって提案された修正された行方不明の処分、新しい選択肢にオープンイムは
を見て試してみてくださいこれはテクスチャスケーリングのためのものです。あなたがOpenGLを初めて使ったからです。https://open.gl/textures –
あなたはSpriteBatchを漏らしています。 SpriteBatchesは削除する必要があります。インスタンス化のためにかなりの時間を要する大きなオブジェクトであるため、ゲームの生涯にわたって単一のインスタンスを再利用する必要があります。 – Tenfour04
@ NickClark2016なので、スプライトバッチがなぜfboの中に伸びたninepatchを描画していて、fboなしでレンダリングされているのでしょうか? – Lyoneel