내 디자인으로 인해 NinePatch 객체를 없애고 싶지만 프레임 버퍼를 사용하여 원하는 크기로 텍스처를 초기화 한 다음 해당 텍스처를 내 사용자 정의에 적용합니다. 객체Libgdx - 프레임 버퍼의 텍스처가 화면에 렌더링 될 때 다른 크기
Im는 LibGDX 및 GL에 새로운 기능입니다. 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;
}
내가, 이미지가 너무 작아서 화면에 FBO에게 질감을 그릴
내가 여기에서 모든이의 골격을 잡아 이유는 나도 몰라 할 때
문제는
}
그리고 내 폴더의 유틸리티 클래스 :
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();
}
}
이어서난 스프라이트 생성 때이 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 : 카메라 크기는 디스플레이 모드 크기이며 화면에 붙이거나 확대/축소하거나 이동하지 않습니다.
편집 :이 방법은 그것을 할 수있는 최선의 방법이 아닌 경우
Tenfour04 @ 제안 고정 누락 된 처분, 새로운 대안
보고 시도 이것은 텍스처 스케일링을 위해 OpenGL을 처음 사용한다고 했으므로 https://open.gl/textures –
SpriteBatch가 유출되었습니다. SpriteBatch는 처리해야합니다. 그리고 그것들은 인스턴스화하는데 많은 시간이 걸리는 큰 객체이기 때문에, 게임의 수명 동안 단일 인스턴스를 재사용해야합니다. – Tenfour04
@ NickClark2016 그래서 Spritebatch가 왜 fbo 내부에 펼쳐진 ninepatch를 그리는 지 궁금 해서요. – Lyoneel