onAreaTouched 不行,我可以放一个方法 onAreaTouched 一个扩展 Entity 类的 Sprite,然后在场景中注册: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);
}
}
在我的 MainActivity onCreateScene 方法中:
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);
}