2014-11-06 39 views
0

當我嘗試拆分紋理時,它不起作用,當我在屏幕上繪製它時,它將繪製與原始紋理相同的4個紋理。我使用下面的代碼來分割紋理。TextureRegion拆分不起作用

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())); 
      } 
     } 

然後,紋理將加載到Actor子類中並通過舞臺繪製。

有什麼建議嗎? 謝謝

回答

1

我懷疑你的問題是ImageActor構造函數的第一個參數。通過致電regs[i][j].getTexture()發送完整的紋理。

getTexture()方法TextureRegion返回區域引用的完整紋理。

您應該發送它TextureRegion regs[i][j],並修改您的ImageActor,以便它可以接收和繪製TextureRegion

+0

它的工作原理,謝謝! – RdlP 2014-11-07 16:02:36