onAreaTouched不起作用,我可以在onAreaTouched上放置一个方法来扩展实体类,然后在场景中注册它:mScene.registerTouchArea(mMENU);
我的实体类是:
public class Menu extends Entity implements ITouchArea{
private TiledSprite mPlaySprite;
private final ParallelEntityModifier mMoveInModifie2 = new ParallelEntityModifier(
new ScaleAtModifier(1f, 5f, 1f, 0.5f, 0.5f),
new FadeInModifier(0.1f));
public Menu() {
}
public void init() {
// TODO Auto-generated method stub
this.mPlaySprite = new TiledSprite(0, 0, ResourceManager.MenuoptionTextureRegion,
ResourceManager.getActivity().getVertexBufferObjectManager()) {
@Override
public boolean onAreaTouched(TouchEvent pSceneTouchEvent,
float pTouchAreaLocalX, float pTouchAreaLocalY) {
/* In the event the mute button is pressed down on... */
if (pSceneTouchEvent.isActionDown()) {
Log.e("pollito","Prueba touch");
}
return super.onAreaTouched(pSceneTouchEvent, pTouchAreaLocalX,
pTouchAreaLocalY);
}
};
this.mPlaySprite.setCurrentTileIndex(0);
this.mPlaySprite.setPosition(ResourceManager.getInstance().cameraWidth*0.5f, ResourceManager.getInstance().cameraHeight * 0.5f );
this.attachChild(this.mPlaySprite);
this.setVisible(false);
}
public void show() {
this.setVisible(true);
mMoveInModifie2.reset();
this.mPlaySprite.registerEntityModifier(mMoveInModifie2);
}
public void hide() {
this.setVisible(false);
}
}
在onCreateScene方法的MainActivity中:
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback) {
ResourceManager.loadMenuResources();
mScene = new Scene();
mScene.setBackground(new Background(0.9f,0.9f,0.9f));
mMenu.init();
mScene.registerTouchArea(mMenu);
mScene.attachChild(mMenu);
pOnCreateSceneCallback.onCreateSceneFinished(mScene);
}