android游戏引擎libgdx使用教程12:如何使用tiledmap地图

鸡啄米  •  扫码分享
java代码
  1. package&com.cnblogs.htynkn.game;&&
  2. &&
  3. import&com.badlogic.gdx.applicationlistener;&&&
  4. import&com.badlogic.gdx.gdx;&&&
  5. import&com.badlogic.gdx.files.filehandle;&&&
  6. import&com.badlogic.gdx.graphics.color;&&&
  7. import&com.badlogic.gdx.graphics.gl10;&&&
  8. import&com.badlogic.gdx.graphics.orthographiccamera;&&&
  9. import&com.badlogic.gdx.graphics.g2d.bitmapfont;&&&
  10. import&com.badlogic.gdx.graphics.g2d.tiled.tileatlas;&&&
  11. import&com.badlogic.gdx.graphics.g2d.tiled.tilemaprenderer;&&&
  12. import&com.badlogic.gdx.graphics.g2d.tiled.tiledloader;&&&
  13. import&com.badlogic.gdx.graphics.g2d.tiled.tiledmap;&&&
  14. import&com.badlogic.gdx.math.vector2;&&&
  15. import&com.badlogic.gdx.math.vector3;&&&
  16. import&com.badlogic.gdx.scenes.scene2d.stage;&&&
  17. import&com.badlogic.gdx.scenes.scene2d.ui.image;&&&
  18. import&com.badlogic.gdx.scenes.scene2d.ui.label;&&&
  19. import&com.badlogic.gdx.scenes.scene2d.ui.label.labelstyle;&&
  20. &&
  21. public&class&javagame&implements&applicationlistener&{&&
  22. &&
  23. stage&stage;&&&
  24. float&width;&&&
  25. float&height;&&&
  26. private&tiledmap↦&&&
  27. private&tileatlas&atlas;&&&
  28. private&tilemaprenderer&tilemaprenderer;&&
  29. &&
  30. vector3&camdirection&=&new&vector3(1,&1,&0);&&&
  31. vector2&maxcamposition&=&new&vector2(0,&0);&&
  32. &&
  33. imageℑ&&
  34. &&
  35. @override&&&
  36. public&void&create()&{&&&
  37. final&string&path&=&"map/";&&&
  38. final&string&mapname&=&"tilemap";&&&
  39. filehandle&maphandle&=&gdx.files.internal(path&+&mapname&+&".tmx");&&&
  40. map&=&tiledloader.createmap(maphandle);&&&
  41. atlas&=&new&tileatlas(map,&new&filehandle("map/"));&&&
  42. tilemaprenderer&=&new&tilemaprenderer(map,&atlas,&10,&10);&&&
  43. maxcamposition.set(tilemaprenderer.getmapwidthunits(),&tilemaprenderer&&&
  44. .getmapheightunits());&&&
  45. &&
  46. width&=&gdx.graphics.getwidth();&&&
  47. height&=&gdx.graphics.getheight();&&&
  48. stage&=&new&stage(width,&height,&true);&&&
  49. label&label&=&new&label("fps:",&new&labelstyle(new&bitmapfont(gdx.files&&&
  50. .internal("font/blue.fnt"),&&&
  51. gdx.files.internal("font/blue.png"),&false),&color.black),&&&
  52. "fpslabel");&&&
  53. stage.addactor(label);&&&
  54. gdx.input.setinputprocessor(stage);&&&
  55. }&&
  56. &&
  57. @override&&&
  58. public&void&dispose()&{&&&
  59. //&todo&auto-generated&method&stub&&
  60. &&
  61. }&&
  62. &&
  63. @override&&&
  64. public&void&pause()&{&&&
  65. //&todo&auto-generated&method&stub&&
  66. &&
  67. }&&
  68. &&
  69. @override&&&
  70. public&void&render()&{&&&
  71. gdx.gl.glclear(gl10.gl_color_buffer_bit);&&&
  72. orthographiccamera&c&=&(orthographiccamera)&stage.getcamera();&&&
  73. ((label)&stage.findactor("fpslabel")).settext("fps:&"&&&
  74. +&gdx.graphics.getframespersecond());&&&
  75. stage.act(gdx.graphics.getdeltatime());&&&
  76. tilemaprenderer.render(c);&&&
  77. stage.draw();&&&
  78. }&&
  79. &&
  80. @override&&&
  81. public&void&resize(int&width,&int&height)&{&&&
  82. //&todo&auto-generated&method&stub&&
  83. &&
  84. }&&
  85. &&
  86. @override&&&
  87. public&void&resume()&{&&&
  88. //&todo&auto-generated&method&stub&&
  89. &&
  90. }&&&
  91. }&&

随意打赏

提交建议
微信扫一扫,分享给好友吧。