2

嗨,我正在使用 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);
    }
});

当我单击该按钮时有一个精灵按钮,我正在更改它的纹理区域,但它无法帮助我更改该精灵的图像

4

2 回答 2

5

AndEngineExamples 中有类似的用法,见https://github.com/nicolasgramlich/AndEngineExamples/blob/GLES2/src/org/andengine/examples/UpdateTextureExample.java

于 2012-10-25T13:34:55.847 回答
2

为什么不能只创建两个精灵并切换它们的可见性?我以这种方式打开/关闭声音按钮:

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);
于 2013-03-14T11:39:48.650 回答