日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Libgdx学习笔记:UI之评分组件

發布時間:2025/7/14 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Libgdx学习笔记:UI之评分组件 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>


評分組件。


使用方法:

//?星星上限,亮圖,背景圖 CHRatingBar?chRatingBar?=?new?CHRatingBar(5,?CHRes.asset.starsp_png,?CHRes.asset.starspgray_png); addActor(chRatingBar); //?星星進度 chRatingBar.setRating(1.5f);

代碼展示;

package?com.oahcfly.chgame.core.ui;import?com.badlogic.gdx.graphics.Color; import?com.badlogic.gdx.graphics.Texture; import?com.badlogic.gdx.graphics.g2d.Batch; import?com.badlogic.gdx.scenes.scene2d.Actor; import?com.oahcfly.chgame.core.Chao; import?com.oahcfly.chgame.core.map.CHTiledActor;/***?*?用星型來顯示等級評定*?@author?haocao**/ public?class?CHRatingBar?extends?Actor?{private?float?numStars;private?float?rating;private?CHTiledActor?bgTiledActor;private?Texture?lightTexture,?bgTexture;/***?*?@param?max?最大數量*?@param?lightPngPath*?@param?bgPngPath*/public?CHRatingBar?(float?max,?String?lightPngPath,?String?bgPngPath)?{this.lightTexture?=?Chao.game.getTexture(lightPngPath);this.bgTexture?=?Chao.game.getTexture(bgPngPath);setNumStars(max);}public?void?setNumStars?(float?numStars)?{this.numStars?=?numStars;bgTiledActor?=?new?CHTiledActor(this.bgTexture,?bgTexture.getWidth()?*?numStars,?bgTexture.getHeight());setSize(bgTexture.getWidth()?*?numStars,?bgTexture.getHeight());}@Overridepublic?void?draw?(Batch?batch,?float?parentAlpha)?{Color?color?=?getColor();batch.setColor(color.r,?color.g,?color.b,?color.a);bgTiledActor.setPosition(getX(),?getY());bgTiledActor.draw(batch,?parentAlpha);float?tmpx?=?getX();float?tmpy?=?getY();//?進度if?(rating?>?0)?{//?有幾個完整starint?fullx?=?(int)rating;for?(int?i?=?0;?i?<?fullx;?i++)?{batch.draw(lightTexture,?tmpx,?tmpy);tmpx?+=?lightTexture.getWidth();}float?remainX?=?rating?-?fullx;if?(remainX?>?0)?{float?remainW?=?remainX?*?lightTexture.getWidth();float?u?=?0,?v?=?1;float?u2?=?remainX,?v2?=?0;batch.draw(lightTexture,?getX()?+?fullx?*?lightTexture.getWidth(),?getY(),?remainW,?lightTexture.getHeight(),?u,?v,u2,?v2);}}}public?float?getMax?()?{return?numStars;}public?float?getRating?()?{return?rating;}public?void?setRating?(float?rating)?{if?(rating?>?numStars)?rating?=?numStars;this.rating?=?rating;}}



基于Libgdx開發的開源游戲框架CHGame:

http://git.oschina.net/oahcfly/CHGameFrame


轉載于:https://my.oschina.net/oahcfly/blog/591600

總結

以上是生活随笔為你收集整理的Libgdx学习笔记:UI之评分组件的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。