简体   繁体   English

TextureRegion拆分不起作用

[英]TextureRegion split doesn't work

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. 当我尝试分割纹理时,它不起作用,当我在屏幕上绘制时,它会绘制与原始纹理相同的4个纹理。 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. 然后将纹理加载到Actor子类中,并通过舞台进行绘制。

Any advice? 有什么建议吗? Thanks 谢谢

I suspect that your problem is in the first argument of the ImageActor constructor. 我怀疑您的问题出在ImageActor构造函数的第一个参数中。 You are sending the full texture by calling regs[i][j].getTexture() . 您正在通过调用regs[i][j].getTexture()发送完整纹理。

The getTexture() method of a TextureRegion returns the full texture that the Region references. getTexture()一个的方法TextureRegion返回质感十足的区域引用。

You should send it the TextureRegion regs[i][j] , and modify your ImageActor so it can receive and draw a TextureRegion . 您应该向其发送TextureRegion regs[i][j] ,并修改ImageActor使其可以接收和绘制TextureRegion

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM