我正在创建2d游戏,它只是libgdx中的等距图,它是64x32
public class MyGdxGame extends ApplicationAdapter implements InputProcessor
{
public static float zoom=0.3f;
Texture img;
TiledMap tiledMap;
OrthographicCamera camera;
TiledMapRenderer tiledMapRenderer;
final Matrix4 matrix = new Matrix4();
public static float lastx,lasty;
private IsometricTiledMapRenderer renderer;
SpriteBatch sb;
Texture texture;
Sprite sprite;
TextureRegion textureRegion;
public static float translate,pick;
TiledMapTileLayer.Cell cell;
TiledMapTileLayer tileLayer;
@Override
public void create () {
float w = Gdx.graphics.getWidth();
float h = Gdx.graphics.getHeight();
camera = new OrthographicCamera();
camera.setToOrtho(false,w,h);
tiledMap = new TmxMapLoader().load("iso.tmx");//iso
renderer = new IsometricTiledMapRenderer(tiledMap);
camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.update();
Gdx.input.setInputProcessor(this);
sb = new SpriteBatch();
texture = new Texture(Gdx.files.internal("sand_128x64.png"));
sprite = new Sprite(texture);
sprite.setSize(50,50);
int mapWidth = tiledMap.getProperties().get("width",Integer.class);
int mapHeight = tiledMap.getProperties().get("height",Integer.class);
}
@Override
public void render () {
Gdx.gl.glClearColor(.5f, .7f, .9f, 1);
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.zoom = zoom;
camera.update();
renderer.setView(camera);
renderer.render();
sb.setProjectionMatrix(camera.combined);
sb.begin();
//sprite.draw(sb);
sb.end();
}
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
lastx=-screenX;
lasty=screenY;
Vector3 clickCoordinates = new Vector3(screenX,screenY,0);
Vector3 position = camera.unproject(clickCoordinates);
//sprite.setPosition(position.x, position.y);
translate=position.x;
return false;
}
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
lastx=0;
lasty=0;
return false;
}
@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
if (lastx != 0) {
camera.translate(-screenX - lastx, screenY - lasty);
lastx = -screenX;
lasty = screenY;
}
return false;
}
@Override
public boolean mouseMoved(int screenX, int screenY) {
return false;
}
@Override
public boolean scrolled(int amount) {
return false;
}
@Override
public boolean keyDown(int p1)
{
// TODO: Implement this method
return false;
}
@Override
public boolean keyUp(int p1)
{
// TODO: Implement this method
return false;
}
@Override
public boolean keyTyped(char p1)
{
// TODO: Implement this method
return false;
}
}
现在我想在触摸时选择贴砖,所以我得到了贴砖(x,y),我尝试了很多方法来做到这一点,但是我找不到很好的解决方案,所以我尝试了此]]
LibGDX: How to make tiled map tiles clickable?
但是它没有用,那我该怎么办?
我正在创建2D游戏,它只是libgdx中的等距图,它是64x32公共类MyGdxGame扩展了ApplicationAdapter实现InputProcessor {public static float zoom = 0.3f;纹理...
问题是,等轴测图是旋转的正方形,因此您无法放置可点击的正方形