2013-02-07 28 views
1

我有一個背景紋理,並希望將其更改爲其他背景紋理。我已經閱讀並測試了一些關於背景紋理的樣本,但第二個背景並沒有顯示。如何更改AndEngine上的背景紋理?

這是我用來嘗試更改的最後一個代碼...任何人都可以提供幫助嗎? 感謝

Scene scene1 = new Scene(); 
    ITexture backgroundTexture1 = null; 
    try { 
     backgroundTexture1 = new BitmapTexture(this.getTextureManager(), new IInputStreamOpener() { 
      @Override 
      public InputStream open() throws IOException { 
       return getAssets().open("gfx/crackedscreen.png"); 
      } 
     }); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
    backgroundTexture1.load(); 
    this.mBackgroundTextureRegion1 = TextureRegionFactory.extractFromTexture(backgroundTexture1); 
    Sprite backgroundSprite = new Sprite(0, 0, this.mBackgroundTextureRegion1, getVertexBufferObjectManager()); 
    scene1.attachChild(backgroundSprite); 
    scene1.setBackgroundEnabled(true); 
    return scene1; 
+0

只是改變加載到這個區域mBackgroundTextureRegion1 –

+0

我已經更新了代碼的質感,加載新的紋理,但沒有變化。仍然顯示第一個背景。謝謝。 – user1847912

回答

2

我使用精靈也遇到了一些麻煩不斷變化的背景。我終於成功使用了SpriteBackground。只需從你的精靈創建一個:

SpriteBackground background = new SpriteBackground(backgroundSprite); 

與其說attachchild的,打電話的setBackground:

scene.setBackground(background);