gpt4 book ai didi

java - 更改 libgdx 中的图像

转载 作者:行者123 更新时间:2023-12-01 12:27:11 24 4
gpt4 key购买 nike

所以我对 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();
}

这是我所拥有的,水平方向上的第二个纹理区域,我想将其放在垂直方向上,删除前一个。请帮忙!

最佳答案

有很多方法可以满足您的需求,因此我建议您尝试阅读 Libgdx 上提供的一些文档。还有Games From Scratch有一些很好的教程。

但这不是您要求的,所以...完成您想要的事情的最简单方法之一是使用 Stage and Actors

操作步骤:

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

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

关于java - 更改 libgdx 中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26237351/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com