Button 클래스를 사용하여 Button을 만들었지 만 ImageTextButton을 사용해 보았습니다. 그러나 Button 클래스만으로도 .json 파일과 함께 .pack (atlas) 파일이 함께 작동하는 방법에 대한 문서를 꽤 따르지는 않습니다.Libgdx ImageTextButton의 LabelStyle 글꼴이 누락되었습니다.
Button 클래스를 사용하면 코드에서 원하는대로 단추를 '이름 지정'하고 해당 json에 따라 이름을 지정할 수 있지만 (아래 예 참조) '이미지의 경우'이름을 모두 같게해야합니다 , 코드의 작성에서 팩 및 json 파일을 통해. 어떤 작품의 예 :
코드 :
// note the 'Constants' just point to the json and atlas files, respectively.
skinShops = new Skin(Gdx.files.internal(Constants.SKIN_SHOPS), new
TextureAtlas(Constants.TEXTURE_ATLAS_SHOPS));
// for this next line, note the json definition for Button$ButtonStyle:
Button buttonBuy = new Button(skinShops, "Button-Buy");
// for Images, it seems I cannot have a 'unique' name first, then the drawable name, which I thought refers to the json
Image imgItemsBackground = new Image(skinShops, "shop-items-background");
당신이 보면 'scene2d.ui.Image :'정의는 모든 같은 지정됩니다. 이 방법으로 작동하는 동안, 나는 왜 명확하지 않다.
이것은 두 가지 질문 일 수 있습니다. 이전의 모든 요소 간 명명의 명명법에 대한 우려가 있었지만 현재의 문제는 과거에 얻을 수없는 것이 ImageTextButton을 구성하려는 것입니다. 코드에서 저는 플레이어가 어디에 있느냐에 따라 이들을 동적으로 구성하고 있습니다. 다른 상점에는 판매 할 항목이 다르며 items [] 배열로 읽습니다.
ImageTextButton buttonPurchase = new ImageTextButton(items[j], skinShops, "shop_item-button-background");
스택 추적 :
Exception in thread "LWJGL Application" java.lang.IllegalArgumentException: Missing LabelStyle font.
at com.badlogic.gdx.scenes.scene2d.ui.Label.setStyle(Label.java:78)
at com.badlogic.gdx.scenes.scene2d.ui.Label.<init>(Label.java:72)
at com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton.<init>(ImageTextButton.java:57)
at com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton.<init>(ImageTextButton.java:44)
at com.uv.screen.InteriorScreen.buildItemButtons(InteriorScreen.java:134)
내가이 버튼의 글꼴을 설정/작성해야 하는가?
JSON 파일 :
{
com.badlogic.gdx.scenes.scene2d.ui.Button$ButtonStyle: {
Button-Exit: { down: Button_Exit_112x60, up: Button_Exit_112x60 },
Button-Buy: { down: Button_Buy_112x60, up: Button_Buy_112x60 },
Button-Sell: { down: Button_Sell_112x60, up: Button_Sell_112x60 }
},
com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton$ImageTextButtonStyle: {
shop_item-button-background: { down: shop_item-button-background, up: shop_item-button-background }
},
com..badlogic.gdx.scenes.scene2d.ui.Image: {
background: { drawable: background },
shop-items-background: { drawable: shop-items-background },
shop-menu-background: { drawable: shop-menu-background },
shop-talk-text-background: { drawable: shop-talk-text-background },
weapon-shop-portrait_world1: { drawable: weapon-shop-portrait_world1 },
armor-shop-portrait_world1: { drawable: armor-shop-portrait_world1 },
item-shop-portrait_world1: { drawable: item-shop-portrait_world1 },
inn-shop-portrait_world1: { drawable: inn-shop-portrait_world1 }
}
아틀라스 파일 : 당신의 JSON에 이미지가 그들에 드로어 블과 동일한 이름을 가져야 이유가
shops-pack.png
format: RGBA8888
filter: Nearest,Nearest
repeat: none
background
rotate: false
xy: 0, 504
size: 800, 480
orig: 800, 480
offset: 0, 0
index: -1
shop-items-background
rotate: false
xy: 0, 248
size: 608, 256
orig: 608, 256
offset: 0, 0
index: -1
shop_item-button-background
rotate: false
xy: 0, 60
size: 256, 60
orig: 256, 60
offset: 0, 0
index: -1
...
필자는 필자의 추적에서 필자가 선택하지 않은 글꼴의 TextButtonStyle 상속을보기 위해 충분히 돌아 가지 않았다. 필자는 저의 오래된 프로젝트를 보면서 실제로 자산과 json 스킨에 글꼴과 .fnt 파일이 생성 된 다음, FreeTypeFontGenerator를 사용하는 또 다른 글꼴 집합이있는 두 가지 방법으로 글꼴을 작성했습니다. 나는 그 일을하기 위해 'SmartFontGenerator'클래스를 만들었다. 나는 내가 그곳에서 한 것을 다시 배울 필요가있다. 내가 피부 경로를 간다면, 내 버튼 생성에 더 많은 것을해야 할 것입니다. 맞습니까? –
Image 및 json에서 약간을 명확히 할 수 있습니까? 정의 된 모든 이미지는 버튼이 아닌 배경으로 사용됩니다. Stack에 추가 된 Table에 이미지를 추가하고 마지막으로 Stage에 이미지를 추가합니다. 그런 다음 버튼이 생성되고 위에 배치됩니다. 그래서 Image 객체를 만드는 것만 큼 똑같은 이름을 지어야합니다. –
ImageButtonStyle 또는 ImageTextButtonStyle을 보면 이미지 매개 변수가 없음을 알 수 있습니다. 그들은 Drawables입니다. 내 생각에 이미지의 이름을 포함 된 드로어 블과 같은 이름으로 지정해야한다고 생각하게하는 것 같습니다. 실제로 Json에서 정의하는 이미지는 완전히 사용되지 않을 것입니다. (당신이 그것을 확인하고 싶다면 Json의 Image 부분을 지우십시오.) 스킨이 Json을 로딩 할 때, 그 이름을 가진 Drawables를 찾고, 특정 이름으로 Drawable을 찾지 못하면 자동으로 하나는 그 이름의 TextureRegion을 사용합니다. – Tenfour04