2014-05-11 2 views
5

나만의 것인지 모르겠지만 drawables 나를 혼란스럽게합니다. 그들은 주어진 크기를 유지하려고합니까, 아니면 그 안에 이미지의 크기를 조절할 수있는 방법이 있습니까? 이미지를 늘려서 특정 영역을 채우기 위해 ninepatch를 사용할 수는 있지만 이미지가 늘어나도록 크기를 조정하려고합니다. 내 메뉴 버튼에 TextButton 을 사용하고 있지만 크기가 너무 커서 배율을 조정하는 방법을 알고 싶습니다. 나는 아틀라스에서 9 패치 이미지가있는 스킨을 가져옵니다. 여기 scene2d 버튼 libgdx로 크기 조정

buttonAtlas = new TextureAtlas(Gdx.files.internal("buttons/buttons.pack")); 
buttonSkin = new Skin(buttonAtlas); 

그 메뉴 버튼의 초기화이다 : The settings screen 여기 내가 사용하고 팩의 이미지입니다 : 여기 ninepatch images packed 이 TextureAtlas의 초기화이다가, 스킨 여기 는 설정 화면입니다 .

TextButtonStyle textButtonStyle = new TextButtonStyle(); 
textButtonStyle.up = Assets.buttonSkin.getDrawable("bluebutton"); 
textButtonStyle.down = Assets.buttonSkin.getDrawable("redbutton"); 
textButtonStyle.font = font; 

buttonMenu = new TextButton("Menu", textButtonStyle); 
buttonMenu.pad(20.0f); 
buttonMenu.addListener(new ClickListener() { 
    @Override 
    public void clicked(InputEvent event, float x, float y) { 
     game.fade.startFadeOut(); 
     super.clicked(event, x, y); 
    } 
}); 

아마도 내가 테이블에 넣는 방식을 바꾸거나 무대에 테이블을 놓을 수 있습니까? 나는 내가 확장 할 수있는 내 자신의 텍스트 버튼 배우를 만드는 시도 할 수도있을 것 같군요 최후의 수단으로

table.add(buttonMenu).width(Gdx.graphics.getWidth()/4); 
stage.addActor(table); 

은, 시간 내 주셔서 감사합니다.

답변

1

우선 이미지가 너무 크다는 것을 알고 있다면 : 이미지 자체를 더 작은 크기로 확대 한 다음 TexturePacker를 사용하여 작은 이미지가 포함 된 새로운 TextureAtlas를 생성하는 것이 가장 좋습니다. 당신이 정말로, 예를보고 싶다면

어쨌든 당신이 TableLayout을 가진 이미지 버튼을 확장 할 수 있습니다 :

table.add(buttonMenu).width(100).height(100); 
0

나를 위해 위의 대답 didnt 한 작업,하지만 난 해결책을 가지고 있습니다.

보조 카메라를 만들어 무대에 부착 할 수 있습니다. 는

예는 것 테이블이 단지 보조 카메라의 뷰포트 크기를 확장 확장하려면 : 터치 컨트롤을 사용할 때이 위대한 작품을

//Heres where you set the scale of your buttons and your table 
Camera secondaryCamera = new Camera(Gdx.graphics.getWidth() * scale, 
            Gdx.graphics.getHeight() * scale); 


Stage stage = new Stage(); 
Table table = new Table(); 
ImageButton button = new ImageButton(drawableUp, drawableDown, drawableChecked); 
table.setFillParent(true); 

stage.getViewport().setCamera(secondaryCamera); 

table.add(ImageButton); 
stage.addActor(table); 

. 전체 UI에 대해 표를 사용하고 다른 게임 항목과 독립적으로 원하는대로 확장 할 수 있습니다.

0

table.add(buttonMenu).width(100).height(100); 작업을해야합니다, 당신은 당신의 취향에 맞게 widthheight 매개 변수를 조정해야하거나 setBounds 방법을 사용할 수 있습니다.

TextButton myButton = new TextButton("Press Me", style); 
    myButton.setBounds(xCoordinate, yCoordinate, width, height); 
0

당신은 크기를 조정 ButtonStyleDrawable의 크기를 설정할 수 있습니다 Button :

UI 위젯이 설정되어 있지 않습니다

float scale = 0.5f; 
float currentHeight = textButtonStyle.up.getMinHeight(); 
textButtonStyle.up.setMinHeight(currentHeight * scale); 

자세한 내용은 official document for layout 참조 다음은 예입니다 그들 자신의 크기와 위치. 대신 상위 위젯은 각 하위의 크기와 위치를 설정합니다. 위젯은 부모가 힌트로 사용할 수있는 최소, 선호 및 최대 크기를 제공합니다. 테이블 및 컨테이너와 같은 일부 상위 위젯에는 하위 항목의 크기 및 위치 지정 방법에 대한 제약 조건을 지정할 수 있습니다. 레이아웃에서 위젯에 특정 크기를 부여하기 위해 위젯의 최소, 기본 및 최대 크기는 그대로두고 크기 제약 조건은 부모에 설정됩니다.

그리고 당신은 source code에서 Button.getPrefHeight()의 구현을 찾을 수 있습니다

public float getPrefHeight() { 
    float height = super.getPrefHeight(); 
    if (style.up != null) height = Math.max(height, style.up.getMinHeight()); 
    if (style.down != null) height = Math.max(height, style.down.getMinHeight()); 
    if (style.checked != null) height = Math.max(height, style.checked.getMinHeight()); 
    return height; 
}