您可以在纹理上使用“ SetWrap”,然后基于该纹理创建一个TextureRegion。创建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);
重要:我花了一段时间才弄清楚,但要进行镜像,您的纹理必须是两倍大小的幂。它可以在Android上运行,但不能在iOS上运行,并且您不会收到消息-它显示为黑色。因此它必须是4x4或8x8、16x16 .. 256x256或512x512 ..
会给你这个:
在下面,您可以看到使用舞台和图像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();
}
}