android游戏引擎libgdx使用教程12:如何使用tiledmap地图
java代码
- package&com.cnblogs.htynkn.game;&&
- &&
- import&com.badlogic.gdx.applicationlistener;&&&
- import&com.badlogic.gdx.gdx;&&&
- import&com.badlogic.gdx.files.filehandle;&&&
- import&com.badlogic.gdx.graphics.color;&&&
- import&com.badlogic.gdx.graphics.gl10;&&&
- import&com.badlogic.gdx.graphics.orthographiccamera;&&&
- import&com.badlogic.gdx.graphics.g2d.bitmapfont;&&&
- import&com.badlogic.gdx.graphics.g2d.tiled.tileatlas;&&&
- import&com.badlogic.gdx.graphics.g2d.tiled.tilemaprenderer;&&&
- import&com.badlogic.gdx.graphics.g2d.tiled.tiledloader;&&&
- import&com.badlogic.gdx.graphics.g2d.tiled.tiledmap;&&&
- import&com.badlogic.gdx.math.vector2;&&&
- import&com.badlogic.gdx.math.vector3;&&&
- import&com.badlogic.gdx.scenes.scene2d.stage;&&&
- import&com.badlogic.gdx.scenes.scene2d.ui.image;&&&
- import&com.badlogic.gdx.scenes.scene2d.ui.label;&&&
- import&com.badlogic.gdx.scenes.scene2d.ui.label.labelstyle;&&
- &&
- public&class&javagame&implements&applicationlistener&{&&
- &&
- stage&stage;&&&
- float&width;&&&
- float&height;&&&
- private&tiledmap↦&&&
- private&tileatlas&atlas;&&&
- private&tilemaprenderer&tilemaprenderer;&&
- &&
- vector3&camdirection&=&new&vector3(1,&1,&0);&&&
- vector2&maxcamposition&=&new&vector2(0,&0);&&
- &&
- imageℑ&&
- &&
- @override&&&
- public&void&create()&{&&&
- final&string&path&=&"map/";&&&
- final&string&mapname&=&"tilemap";&&&
- filehandle&maphandle&=&gdx.files.internal(path&+&mapname&+&".tmx");&&&
- map&=&tiledloader.createmap(maphandle);&&&
- atlas&=&new&tileatlas(map,&new&filehandle("map/"));&&&
- tilemaprenderer&=&new&tilemaprenderer(map,&atlas,&10,&10);&&&
- maxcamposition.set(tilemaprenderer.getmapwidthunits(),&tilemaprenderer&&&
- .getmapheightunits());&&&
- &&
- width&=&gdx.graphics.getwidth();&&&
- height&=&gdx.graphics.getheight();&&&
- stage&=&new&stage(width,&height,&true);&&&
- label&label&=&new&label("fps:",&new&labelstyle(new&bitmapfont(gdx.files&&&
- .internal("font/blue.fnt"),&&&
- gdx.files.internal("font/blue.png"),&false),&color.black),&&&
- "fpslabel");&&&
- stage.addactor(label);&&&
- gdx.input.setinputprocessor(stage);&&&
- }&&
- &&
- @override&&&
- public&void&dispose()&{&&&
- //&todo&auto-generated&method&stub&&
- &&
- }&&
- &&
- @override&&&
- public&void&pause()&{&&&
- //&todo&auto-generated&method&stub&&
- &&
- }&&
- &&
- @override&&&
- public&void&render()&{&&&
- gdx.gl.glclear(gl10.gl_color_buffer_bit);&&&
- orthographiccamera&c&=&(orthographiccamera)&stage.getcamera();&&&
- ((label)&stage.findactor("fpslabel")).settext("fps:&"&&&
- +&gdx.graphics.getframespersecond());&&&
- stage.act(gdx.graphics.getdeltatime());&&&
- tilemaprenderer.render(c);&&&
- stage.draw();&&&
- }&&
- &&
- @override&&&
- public&void&resize(int&width,&int&height)&{&&&
- //&todo&auto-generated&method&stub&&
- &&
- }&&
- &&
- @override&&&
- public&void&resume()&{&&&
- //&todo&auto-generated&method&stub&&
- &&
- }&&&
- }&&