【问题标题】:How to render Sprites normally on rotated isometric tiles? LIBGDX如何在旋转的等距图块上正常渲染 Sprite? LIBGDX
【发布时间】:2015-07-28 00:44:26
【问题描述】:

我正在使用本教程从普通 Sprite 制作等距地图: http://www.badlogicgames.com/wordpress/?p=2032

我想在我的地砖上的位置 0,0 处渲染一座房子,但它看起来像这样: http://gyazo.com/c7d5cd74829150c684cfa7b40c9fdfba

这是我的 create() 和 render():

@Override
public void create () {
    batch = new SpriteBatch();
    img = new Texture(Gdx.files.internal("grass2d.jpg"));

    //House
    house = new Sprite(new Texture(Gdx.files.internal("mb_0004.png")));
    house.setSize(2,2);
    house.setPosition(0,0);


    // Camera
    cam = new OrthographicCamera(10,10*(Gdx.graphics.getHeight()/(float)Gdx.graphics.getWidth()));
    cam.position.set(5,5,10);
    cam.direction.set(-1,-1,-1);
    cam.near = 1;
    cam.far = 100;
    //Matrices
    //Matrix to rotate floor tiles
    matrix.setToRotation(new Vector3(1,0,0), 90);
    // Subject to change?
    matrix2.setToRotation(new Vector3(0,1,0),45);

    // populate Tiles
    for(int z = 0; z < 100; z++) {
        for(int x = 0; x < 100; x++) {
            sprites[x][z] = new Sprite(img);
            sprites[x][z].setPosition(x,z);
            sprites[x][z].setSize(1, 1);
        }
    }




    Gdx.input.setInputProcessor(this);

}


@Override
public void render () {
    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    cam.update();
    batch.setProjectionMatrix(cam.combined);
    batch.setTransformMatrix(matrix);

    batch.begin();
    for(int z = 0; z < 100; z++) {
        for(int x = 0; x < 100; x++) {
            sprites[x][z].draw(batch);
        }
    }

    batch.end();
    batch.begin();



    //batch.setTransformMatrix(matrix2);
    house.draw(batch);
    batch.end();

我确实尝试创建另一个矩阵来将其转换回来,但后来我的坐标被弄乱了。希望大家帮忙。

【问题讨论】:

    标签: matrix libgdx isometric


    【解决方案1】:

    我能够使用 TiledMap 和一个自写的算法来检测是否点击了一个图块以及哪个图块。我现在可以用鼠标放置我的房子了,我真的很喜欢这个结果。

    如果有人有兴趣,我会花一些时间写一个小教程。

    这是目前的样子: Isometric Tiles

    【讨论】:

      猜你喜欢
      • 2016-02-27
      • 1970-01-01
      • 1970-01-01
      • 2021-07-07
      • 1970-01-01
      • 1970-01-01
      • 2014-11-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多