When I try to split a texture it doens't work, when I draw it in screen it draw the same 4 textures that are the same that original Texture. I use the following code to split a texture.
texture = new Texture(Gdx.files.internal("fondo1.png"));
TextureRegion[][] regs = TextureRegion.split(texture, texture.getWidth() / 2, texture.getHeight() / 2);
Random rand = new Random();
int x,y;
for (int i=0; i < regs.length; i++){
for (int j = 0; j < regs[i].length; j++){
x = rand.nextInt(500);
y = rand.nextInt(500);
parts.add(new ImageActor(regs[i][j].getTexture(),x,y, regs[i][j].getRegionWidth(), regs[i][j].getRegionHeight()));
}
}
The textures then are loaded in an Actor subclass and draw via stage.
Any advice? Thanks
I suspect that your problem is in the first argument of the ImageActor
constructor. You are sending the full texture by calling regs[i][j].getTexture()
.
The getTexture()
method of a TextureRegion
returns the full texture that the Region references.
You should send it the TextureRegion regs[i][j]
, and modify your ImageActor
so it can receive and draw a TextureRegion
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.