我在TiledMap上绘制图像(纹理)时遇到问题。当我尝试调用batch.draw(mytexture,x,y)时,显示的唯一图像是下面的地图;我试图在网上搜索一个可行的解决方案,但我还没有解决问题..
我
这是我的代码
public class GameTest implements ApplicationListener{
private Player player;
private Batch batch;
private MyTexture texture;
private OrthographicCamera camera;
private OrthogonalTiledMapRenderer renderer;
private TiledMap map;
public GameTest() {
//init camera and player
}
@Override
public void create() {
background = new Background();
batch = new SpriteBatch();
texture = new MyTexture();
map = new TmxMapLoader().load(Asset.FIRST_LEVEL);
renderer = new OrthogonalTiledMapRenderer(map);
camera.setToOrtho(false, 1280,512);
renderer.setView(camera);
camera.update();
}
@Override
public void render() {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
background.update(Gdx.graphics.getDeltaTime());
batch.begin();
if(Gdx.input.isKeyJustPressed(Input.Keys.RIGHT)){
game.movePlayer('r', 1);
camera.position.x += 5;
}
camera.update();
renderer.setView(camera);
renderer.render();
// batch.setProjectionMatrix(camera.combined);
batch.draw(texture.getTexture("100"), (player.getPosition().y) * 64, ((7
- player.getPosition().x) * 64));
batch.end();
}
}
这是MyTexture课程。我创建了一个地图,我将一个String作为一个键,一个Texture对应于我想要显示的图像
public MyTexture() {
....
map.put("100",new Texture(Gdx.files.internal(Asset.PLAYER)));
}
public static final Texture getTexture(String key){
return map.get(key);
}
这是我的Asset类,我只为imgaes路径创建静态字段 公共类资产{
public static Map<String, String> map = new HashMap<String,String>();
public static final String FIRST_LEVEL = "levels/firstLevel.tmx";
public static String BACKGROUND = "asset/Background.png";
public static String PLAYER = "asset/Player.png";
...
}