偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

Android游戲引擎libgdx使用教程11:Skin和UI配置文件

移動(dòng)開(kāi)發(fā) Android
ibgdx的UI改進(jìn)很大,原來(lái)各種稀奇古怪的問(wèn)題都已經(jīng)解決了,而且UI的類型也基本上完全了。推薦大家下載最近的版本使用。

ibgdx的UI改進(jìn)很大,原來(lái)各種稀奇古怪的問(wèn)題都已經(jīng)解決了,而且UI的類型也基本上完全了。推薦大家下載最近的版本使用。

UI的使用我覺(jué)得唯一復(fù)雜的就是各種樣式的制定,比如TextButton:

  1. public TextButtonStyle (NinePatch down, NinePatch up, NinePatch checked, float pressedOffsetX, 
  2. float pressedOffsetY,float unpressedOffsetX, float unpressedOffsetY, 
  3. BitmapFont font, Color fontColor, Color downFontColor,Color checkedFontColor)   

再看看List:

public ListStyle (BitmapFont font, Color fontColorSelected, Color fontColorUnselected, NinePatch selectedPatch)

每次使用都需要實(shí)例化若干個(gè)Texture,NinePatch什么的還是有點(diǎn)麻煩,還好libgdx給出了一個(gè)解決方案:Skin。

Skin保存了UI的樣式和相關(guān)的資源,定義使用的是Json或者Json-like。API地 址:http://libgdx.l33tlabs.org/docs/api/com/badlogic/gdx/scenes/scene2d/ui /Skin.html

先看看基本格式:

  1. {     
  2. resources: {     
  3. className: {     
  4. name: value,     
  5. ...     
  6. },     
  7. ...     
  8. },     
  9. styles: {     
  10. className: {     
  11. name: value,     
  12. ...     
  13. },     
  14. ...     
  15. }     
  16. }     

由兩個(gè)大塊定義:資源和樣式。先做個(gè)fnt文件以便支持中文。

Android游戲引擎libgdx使用教程11:如何使用Skin和UI配置文件

保持為chinese.fnt和chinese.png。再做張圖:

Android游戲引擎libgdx使用教程11:如何使用Skin和UI配置文件

全部拷貝到項(xiàng)目文件中(我是新建了一個(gè)UI文件夾)。我們先寫(xiě)個(gè)Label試試。定義需要的NinePath:

  1. com.badlogic.gdx.graphics.g2d.NinePatch: {    
  2. default-rect-red: [    
  3. { width: 2, height: 1, x: 1, y: 43 },    
  4. { width: 1, height: 1, x: 2, y: 43 },    
  5. { width: 2, height: 1, x: 3, y: 43 },    
  6. { width: 2, height: 1, x: 1, y: 45 },    
  7. { width: 1, height: 1, x: 2, y: 45 },    
  8. { width: 2, height: 1, x: 3, y: 45 },    
  9. { width: 2, height: 1, x: 1, y: 43 },    
  10. { width: 1, height: 1, x: 2, y: 43 },    
  11. { width: 2, height: 1, x: 3, y: 43 }    
  12. ],    
  13. default-rect-yellow: [    
  14. { width: 2, height: 1, x: 1, y: 54 },    
  15. { width: 1, height: 1, x: 2, y: 54 },    
  16. { width: 2, height: 1, x: 3, y: 54 },    
  17. { width: 2, height: 1, x: 1, y: 55 },    
  18. { width: 1, height: 1, x: 2, y: 55 },    
  19. { width: 2, height: 1, x: 3, y: 55 },    
  20. { width: 2, height: 1, x: 1, y: 54 },    
  21. { width: 1, height: 1, x: 2, y: 54 },    
  22. { width: 2, height: 1, x: 3, y: 54 }    
  23. ]    
  24. }   

再定義一個(gè)白色:

  1. com.badlogic.gdx.graphics.Color: {    
  2. white: { a: 1, b: 1, g: 1, r: 1 }    
  3. }   

然后我們的字體:

  1. com.badlogic.gdx.graphics.g2d.BitmapFont: {    
  2. default-font: { file: chinese.fnt }    
  3. }   

然后在樣式中聲明一個(gè)Label樣式:

  1. com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle: {    
  2. default: { font: default-font, fontColor: white}    
  3. }   

使用時(shí):

  1. Skin skin = new Skin(Gdx.files.internal("ui/uiskin.json"), Gdx.files.internal("ui/ui.jpg")); //加載樣式   
  2.    
  3. final Label label = new Label("FPS:", skin.getStyle("default",LabelStyle.class), "fpsLabel"); //獲取Label樣式   

效果:

Android游戲引擎libgdx使用教程11:如何使用Skin和UI配置文件

然后再來(lái)試試TextButton:

  1. com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle: {    
  2. default: { down: default-rect-red, up: default-rect-yellow,fontColor: white, font: default-font}    
  3. }   

 調(diào)用:

  1. final TextButton textButton = new TextButton("確認(rèn)", skin.getStyle("default", TextButtonStyle.class), "okButton");   

效果:

Android游戲引擎libgdx使用教程11:如何使用Skin和UI配置文件

 

按下去的時(shí)候會(huì)變黃(沒(méi)截起圖)…

Skin真的用著很方便,特別是你大量使用了libgdx的UI的時(shí)候。

寫(xiě)在最后:

1、Skin支不支持xml?

說(shuō)實(shí)話我也很想知道,因?yàn)間dx-tests里面skin 的配置文件有兩個(gè),一個(gè)是json格式,另外一個(gè)是xml格式。但是我試了一下直接加載xml會(huì)報(bào)錯(cuò)。

其實(shí)我比較推薦用xml格式,因?yàn)镴son格式書(shū)寫(xiě)時(shí)候容易寫(xiě)錯(cuò)(少個(gè)逗號(hào)或者括號(hào)什么的),而且eclipse的自動(dòng)縮進(jìn)沒(méi)有發(fā)揮作用(難道是配置問(wèn)題?)。

2、Skin支持不一個(gè)配置文件多個(gè)圖片文件,這個(gè)情況推薦將圖片合并或者干脆用多個(gè)Skin就行了。

3、Skin的圖片定義的原點(diǎn)是左上角。

責(zé)任編輯:閆佳明 來(lái)源: jizhuomi
相關(guān)推薦

2013-12-04 13:30:45

Android游戲引擎libgdx教程

2013-12-04 17:14:57

Android游戲引擎libgdx教程

2013-12-06 10:12:49

Android游戲引擎libgdx教程

2013-12-06 10:31:14

Android游戲引擎libgdx教程

2013-12-04 16:28:29

Android游戲引擎libgdx教程

2013-12-06 09:59:53

Android游戲引擎libgdx教程

2013-12-04 17:27:10

Android游戲引擎libgdx教程

2013-12-06 10:22:42

Android游戲引擎libgdx教程

2013-12-04 16:07:27

Android游戲引擎libgdx教程

2013-12-04 16:21:02

Android游戲引擎libgdx教程

2011-07-18 10:53:09

2011-07-18 11:07:12

iPhone 游戲 引擎

2011-07-18 12:29:10

2011-07-18 11:23:29

iPhone 游戲 動(dòng)畫(huà)

2011-07-18 11:39:58

iPhone 游戲 引擎

2010-03-25 18:31:03

Nginx配置文件

2021-07-05 12:09:58

Python編程語(yǔ)言

2022-11-10 09:05:18

Lua配置文件

2010-12-27 14:59:31

Outlook 配置文

2009-06-24 14:17:00

BackingBeanJSF配置文件
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)