【问题标题】:Changing images in libgdx更改 libgdx 中的图像
【发布时间】:2014-12-01 23:01:38
【问题描述】:

所以我是 libGDX 的新手,我正在制作一个游戏,如果你按下它旋转的图像,这意味着它会改变另一个图像。 但我不知道该由谁来做,我需要一些帮助。

@Override
public void create () {

    spriteBatch = new SpriteBatch();
    font = new BitmapFont(true);
    camera = new OrthographicCamera();

    texture = new Texture(Gdx.files.internal("cable_side.png"));
    textureRegion = new TextureRegion(texture);
    textureRegion.flip(false, true);

    texture2 = new Texture(Gdx.files.internal("cable_l_1.png"));
    textureRegion2 = new TextureRegion(texture2);
    textureRegion2.flip(false, true);

    camera.setToOrtho(true, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());


}

@Override
public void render () {


    Gdx.gl.glClearColor(0.4f, 0.4f, 0.4f, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    camera.update();
    spriteBatch.setProjectionMatrix(camera.combined);

    spriteBatch.begin();
    //font.draw(spriteBatch, "Hacking Time", 0, 0);
    spriteBatch.draw(textureRegion2, 0, 0);
    spriteBatch.draw(textureRegion, 32, 0);
    spriteBatch.draw(textureRegion, 64, 0);
    spriteBatch.draw(textureRegion, 96, 0);
    spriteBatch.draw(textureRegion, 128, 0);
    spriteBatch.draw(textureRegion, 160, 0);
    spriteBatch.draw(textureRegion, 192, 0);
    spriteBatch.draw(textureRegion, 224, 0);
    spriteBatch.end();
    }

这就是我所拥有的,第二个textureRegion 在水平方向,我想把它放在垂直方向,删除前一个。 请帮忙!

【问题讨论】:

    标签: java image libgdx textures coordinates


    【解决方案1】:

    有很多方法可以做你想做的事,所以我建议你尝试阅读Libgdx 上的一些文档,Games From Scratch 也有一些很好的教程。

    但这不是你所要求的......完成你想要的最简单的方法之一是使用Stage and Actors。

    步骤:

    1. 创建场景;
    2. 将 Gdx 输入处理器与舞台相关联;
    3. 创建一个皮肤来存储您的 UI 资源;
    4. 使用原始图像的 up 参数创建 ImageButtonStyle,并使用要交换的图像进行检查;
    5. 使用之前的 ImageButtonStyle 创建 ImageButtons。

    这里在另一个Stackoverflow Topic 用户DannyBit 中提供了一个代码片段,它可以执行与文本按钮类似的操作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-17
      • 2014-03-04
      • 1970-01-01
      • 2016-08-30
      • 1970-01-01
      相关资源
      最近更新 更多