您好我正在使用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);
}
});
当我点击该按钮时有一个精灵按钮它的纹理区域我正在改变,但它无法帮助我改变该精灵的图像
答案 0 :(得分:5)
AndEngineExamples中有类似的用法,请参阅https://github.com/nicolasgramlich/AndEngineExamples/blob/GLES2/src/org/andengine/examples/UpdateTextureExample.java
答案 1 :(得分: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);