您可以在纹理上使用“SetWrap”并基于该纹理创建一个 TextureRegion。
重要提示:我花了一段时间才弄清楚,但要进行镜像,您的纹理必须是两倍大小的幂。它可以在 Android 上运行,但不能在 iOS 上运行,并且您没有收到消息 - 它显示为黑色。所以它必须是 4x4 或 8x8、16x16 .. 256x256 或 512x512 .. 创建 3x3 镜像(或 axb 大小)
Texture imgTexture = new Texture(Gdx.files.internal("badlogic.jpg"));
imgTexture.setWrap(Texture.TextureWrap.MirroredRepeat, Texture.TextureWrap.MirroredRepeat);
TextureRegion imgTextureRegion = new TextureRegion(imgTexture);
imgTextureRegion.setRegion(0,0,imgTexture.getWidth()*3,imgTexture.getHeight()*3);
会给你这个:
您可以在下面看到使用舞台和图像 Actor (Scene2D) 生成该图片的示例代码
public class GameScreen implements Screen {
MyGdxGame game;
private Stage stage;
public GameScreen(MyGdxGame aGame){
stage = new Stage(new ScreenViewport());
game = aGame;
Texture imgTexture = new Texture(Gdx.files.internal("badlogic.jpg"));
imgTexture.setWrap(Texture.TextureWrap.MirroredRepeat, Texture.TextureWrap.MirroredRepeat);
TextureRegion imgTextureRegion = new TextureRegion(imgTexture);
imgTextureRegion.setRegion(0,0,imgTexture.getWidth()*3,imgTexture.getHeight()*3);
TextureRegionDrawable imgTextureRegionDrawable = new TextureRegionDrawable(imgTextureRegion);
Image img = new Image();
img.setDrawable(imgTextureRegionDrawable);
img.setSize(imgTexture.getWidth()*3,imgTexture.getHeight()*3);
stage.addActor(img);
}
@Override
public void show() {
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act(delta);
stage.draw();
}
@Override
public void resize(int width, int height) {
stage.getViewport().update(width, height, true);
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void hide() {
}
@Override
public void dispose() {
stage.dispose();
}
}