libgdx学习文档Word格式.docx
- 文档编号:20177436
- 上传时间:2023-01-17
- 格式:DOCX
- 页数:17
- 大小:756.27KB
libgdx学习文档Word格式.docx
《libgdx学习文档Word格式.docx》由会员分享,可在线阅读,更多相关《libgdx学习文档Word格式.docx(17页珍藏版)》请在冰豆网上搜索。
Mesh是如何生成的呢?
众所周知,数学上讲的立体几何由点、线、面三部份组成,不管何等复杂的图像也能够分解为无数细小的这三部份,或说能够由超级基础的N个这三部份所组合而成;
到了3D游戏开发时,当咱们要构建复杂的3D图像,第一会以一系列有序的vertices(极点)组成这些具体的点、线、三角要素,即组成画图大体图元(Primitives),再将大体图元组合成更完整的高级图元也确实是具体3D对象。
因此,若是对Mesh概念进行简单的明白得,其实它确实是一个象征完整图像的大体图元集合体,Libgdx先让咱们把一个个细分的vertices组成大体图元,再由Mesh类将大体图元制成加倍复杂的高级图元展现出来。
具体可见Libgdx作者提供的returntomarchfeld示例,基本效果如下图所示:
(勿看FPS,一切信真机)PS:
若是对此类熟悉不足,能够去玩玩模拟人一辈子,下个修改器尝试编辑角色或物品造型后就懂了……
PS指postscript(备注,又可说明为附言、跋文)的缩写Texture:
Libgdx所提供的游戏纹理用类,其实质可明白得为保留在显存中的Image,它以贴图的方式通过OpenGL将图片显示到游戏界面之上。
Libgdx的纹理能够直接从指定文件途径加载,也能够通过它提供的Pixmap类凭空创建(它的Texture(intwidth,intheight,Formatformat)构造内部直接挪用了Pixmap,不是必需在外部生成Pixmap后注入)。
另外在加载Texture时,个人建议通过Libgdx提供的函数挪用,该方式内部提供了Texture缓存治理,能够幸免无心义的资源重复加载。
另外,Texture通常会与TextureRegion类配套利用,利用TextureRegion包装Texture后,再利用SpriteBatch进行绘制,能够很方便的修订Texture为咱们需要的显示范围。
还有,Libgdx中Sprite类为TextureRegion子类,因此能够将Sprite看成TextureRegion来利用,只是Sprite类比TextureRegion有所扩展。
只是Libgdx的SpriteCache类并无继承Sprite或TextureRegion,因此起不到TextureRegion的作用,只能构建一组静态贴图集合算了,特此说明。
1.MainMainMainnternal("
"
),
false);
2.
}
3.
publicvoid
render(){
1.
Main4a2a-0.5f0.5f0.0f0.0f-0.5f-0.5f0.0f1.0f0.5f-0.5f1.0f1.0f0.5f0.5f1.0f0.0fetHeight());
4.
();
5.
6.
Main-0.5f-0.5f0.5f-0.5f0.5f0.5f4a4a2a0f1f0f0.2f0.2f0.2fetWidth(),
().getHeight(),
false,
true);
resize(int
width,
int
height){
7.
8.
resume(){
9.
10.
}
11.
onCreate(Bundlebundle){
12.
(bundle);
Mainet()){
Main(Sequence.$(ScaleTo.$(1.1f,
1.1f,
0.3f),
ScaleTo.$(1f,1f,
0.3f))));
(img);
dispose(){
13.
14.
pause(){
15.
16.
17.
18.
19.
20.
21.
22.
2月1日2020年1月28日7aDidyounotice,however,thatthetriangleswecreatedappearstretched?
Letsstartwithanexamplethatwillmakethisissueclear.
CreatingaSquare
Createanewlibgdxdesktopprojectnamed
projection-viewport-camera.Createaclasscalled
ProjectionViewportCamera
thatimplementsApplicationListener
andputitinthepackage
Forfullinstructiononhowtosetupalibgdxdesktop(andAndroid)project,lookatthe
tutorial.Unlikeinthattutorial,we'
regoingtoshowasquareinsteadofarectangle.Here'
sthecodefor
ProjectionViewportCamera:
packageimportimportimportimportimportimportimportpublicclassProjectionViewportCameraimplementsApplicationListener{
privateMeshsquarePartOne;
privateMeshsquarePartTwo;
@Override
publicvoidcreate(){
if(squarePartOne==null){
squarePartOne=newMesh(true,3,3,
newVertexAttribute,3,"
a_position"
newVertexAttribute,4,"
a_color"
));
(newfloat[]{
-,-,0,(128,0,0,255),
-,0,(192,0,0,255),
-,,0,(192,0,0,255)});
(newshort[]{0,1,2});
if(squarePartTwo==null){
squarePartTwo=newMesh(true,3,3,
-,,0,(192,0,0,255),
,0,(255,0,0,255)});
publicvoiddispose(){}
publicvoidpause(){}
publicvoidrender(){
0,3);
publicvoidresize(intwidth,intheight){}
publicvoidresume(){}}
It'
sverysimilartotheclassdescribedintheMyFirstTriangleTutorialexceptthatithastwotrianglesinsteadofone.Thetwotrianglesarepositionedtoformasquare,withcornersatposition(x,y)coordinates,,,,,,and,.Whenyourunthedesktopappitshouldlooklikethis:
Obviously,eventhoughwespecifiedthecoordinatesofasquare,theresultingshapeturnedouttobeawiderectangle.Beforetacklingthisissue,Iwilldigressforamomentandofferarenderingoptimzationforthissquare.
Thetwotriangleseachhaveavertexat,andavertexat,.Wecaneliminatetheduplicationofverticesatidenticalcoordinatesbyimplementingthesquareusing
.Usingtrianglestripsallowthetwotrianglestoshareverticesandthereforeusememorymoreefficiently(checkout
forabetterillustration).Here'
sthenewimplementation:
privateMeshsquareMesh;
if(squareMesh==null){
squareMesh=newMesh(true,4,4,
(newshort[]{0,1,2,3});
16
0,4);
Thetwotriangleshavebeencombinedinasinglemeshwithfourverticesandfourindices.Inside
render(),wespecifythatthesquarewasdefinedusingtrianglestrips.Fewerverticesarenecessaryandthecodeissimplertoo.
Viewport
Backtotheissueofthestretchedsquare.Bydefaulttheviewportrevealsarectangularareawithaleftedgeatx=-1,rightedgeatx=1,topedgeaty=1,andbottomedgeaty=-1.Here'
sapictureofwhatablankarealikethatwouldlooklikeifweweretocreatemockup:
Whenweplaceoutredsquareontothatarea,theresultlookslikethis:
However,theviewportitselfiswiderthanasquare.Inordertofilluptheextraspaceonthesides,theareaisstretched.Imagineapainterstretchingasquarecanvastofitarectangularframe.Theresultlookslikewhatweseeinthe
tutorial:
Camera
Tocorrectthiseffect,weallowtheviewporttorenderanareathatisrectangularinsteadofsquare.Theshapeofthisareawillmatchtheshapeofviewport,sortoflikeapainterchoosingacanvassizebasedonthepictureframe'
ssize.Toaccomplishthis,weusethe
Camera
class,inthisacaseasubclasscalled
OrthographicCamera.The
classallowsustochangetheareashownbytheviewport.Here'
sthenewcode:
packageimportimportimportimportimportimportimportimportpublicclassProjectionViewportCameraimplementsApplicationListener{
privateOrthographicCameracamera;
();
;
publicvoidresize(intwidth,intheight){
floataspectRatio=(float)width/(float)height;
camera=newOrthographicCamera(2f*aspectRatio,2f);
In
resize(),weconstructanewinstanceof
OrthographicCamera,specifiyingtheareawewanttodisplay.Inthisexample,wetellthecameratodisplayanareatwounitstall,withawidththatisdeterminedbytheshapeoftheviewport.In
render(),wecallsimplycall
update()
andapply()
onthe
instance.Here'
showitlookswhenweruntheapp:
Thedesktopviewportinourtutorialshavebeen480pixelswideand320pixelshigh.Thesearethenumbersarepassedinto
resize()
whentheappl
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- libgdx 学习 文档
![提示](https://static.bdocx.com/images/bang_tan.gif)