2012-10-25 50 views
2

嗨,我使用Andengine作出Game應用程序變化圖像andengine

中,我要改變一個精靈的背景圖像時,我對精靈點擊

。任何機構都可以幫助我如何做到這一點。

this.mFaceTextureRegionBackOn = TextureRegionFactory.extractFromTexture(this.mTextureBackOn); 
this.mFaceTextureRegionBackOff = TextureRegionFactory.extractFromTexture(this.mTextureBackOff); 

final ButtonSprite back = new ButtonSprite(centerXBack, centerYBack, this.mFaceTextureRegionBackOn, this.getVertexBufferObjectManager()); 
scene.attachChild(back); 
back.setOnClickListener(new OnClickListener() { 

    @Override 
    public void onClick(ButtonSprite arg0, float arg1, float arg2) { 
     MainActivity.this.mFaceTextureRegionBackOn = TextureRegionFactory.extractFromTexture(MainActivity.this.mTextureBackOff); 
    } 
}); 

有一個精靈按鈕時我該按鈕它的紋理區域,我改變點擊,但它不能幫助我改變精靈的形象

回答

2

爲什麼你不能創建兩個精靈並切換其可見性?我以這種方式在\ off按鈕上切換聲音:

soundOnBtn = new Sprite(TILE_SIZE/2, 0, TILE_SIZE, TILE_SIZE, gameResources.getSoundOnTR()) 
    { 
     @Override 
     public boolean onAreaTouched(TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) 
     { 
      soundOn = !soundOn; 
      soundOnBtn.setVisible(soundOn); 
      soundOffBtn.setVisible(!soundOn); 
      return true; 
     } 
    }; 
    mainScene.registerTouchArea(soundOnBtn); 
    soundOffBtn = new Sprite(TILE_SIZE/2, 0, TILE_SIZE, TILE_SIZE, gameResources.getSoundOffTR()); 
    soundOffBtn.setVisible(false); 
    bottomPanelLayer.attachChild(soundOnBtn);  
    bottomPanelLayer.attachChild(soundOffBtn);