在我的代码中,我正在使用以下代码来加载.tmx映射。我也使用IsometricTiledMapRenderer。 我想在平铺上的触摸事件中添加一个单位。
assetManager.setLoader(TiledMap.class, new TmxMapLoader(new InternalFileHandleResolver()));
assetManager.load("maps/grass_and_water.tmx", TiledMap.class);
assetManager.finishLoading();
map = assetManager.get("maps/grass_and_water.tmx");
renderer = new IsometricTiledMapRenderer(map, 1f / 64f);
Gdx.input.setInputProcessor(new GestureDetector(new MapGestureListener(camera, jetFlyingSprite, map)));`
在touchDown中,我试图在单击时添加TextureMapObject。
@Override
public boolean touchDown(float x, float y, int pointer, int button) {
Gdx.app.log(TAG, "touchDown gesture");
flinging = false;
scale = camera.zoom;
//return false;
Vector3 clickCoordinates = new Vector3(x,y,0);
Vector3 position = camera.unproject(clickCoordinates);
Texture texture = new Texture("jet_flying.png");
TextureRegion textureRegion = new TextureRegion(texture,400,400);
MapLayer mapLayer = map.getLayers().get("objects");
mapLayer.setVisible(true);
TextureMapObject textureMapObject = new TextureMapObject(textureRegion);
textureMapObject.setName("plane");
textureMapObject.setX((float)position.x);
textureMapObject.setY((float)position.y);
mapLayer.getObjects().add(textureMapObject);
textureMapObject.setX((float)position.x);
textureMapObject.setY((float)position.y);
return true;
}
运行时,我单击时什么也没发生。
有任何线索/吗?
答案 0 :(得分:0)
我猜您的"objects"
层是一个Object层,该实现在BatchTiledMapRenderer
继承的IsometricTiledMapRenderer
中留为空白。这意味着将渲染对象层。
BatchTiledMapRenderer renderMapLayer
method会调用renderObject
,它看起来像这样:
@Override
public void renderObject (MapObject object) {
}
您可以继承IsometricTiledMapRenderer
并自己实现renderObject
。