我正在创建基于 AndEngine 动态壁纸扩展的动态壁纸。在 onCreateScene() 函数中,我将触摸事件设置为我的场景。这是代码:
@Override
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback) {
mEngine.registerUpdateHandler(new FPSLogger());
parallaxBackground = new ParallaxBackground(0, 0, 0);
parallaxBackground.attachParallaxEntity(new ParallaxEntity(1.0f, mySprite));
mCurrentScene.setBackground(parallaxBackground);
mCurrentScene.setOnSceneTouchListener(this);
pOnCreateSceneCallback.onCreateSceneFinished(mCurrentScene);
}
之后我创建 onSceneTouchEvent() 函数:
@Override
public boolean onSceneTouchEvent(Scene scene, TouchEvent event) {
switch(event.getAction()){
case TouchEvent.ACTION_DOWN:
Log.i("Logged TouchEvent DOWN", ""+event.getAction());
break;
case TouchEvent.ACTION_MOVE:
Log.i("Logged TouchEvent MOVE", ""+event.getAction());
break;
case TouchEvent.ACTION_UP:
Log.i("Logged TouchEvent UP", ""+event.getAction());
break;
}
return true;
}
这段代码一切正常吗?好的。我在我的手机(三星 Galaxy S III mini)上运行它......,当我第一次触摸屏幕时,日志中写着:
AndEngine org.andengine.input.touch.TouchEvent$TouchEventPool<TouchEvent> was exhausted, with 0 item not yet recycled. Allocated 1 more.
Logged TouchEvent DOWN 0
当我第二次触摸屏幕等时,日志中写着:
Logged TouchEvent DOWN 0
Logged TouchEvent DOWN 0
Logged TouchEvent DOWN 0
Logged TouchEvent DOWN 0
.....
...仅检测到 ACTION_DOWN!ACTION_UP 和 ACTION_MOVE 不起作用!
也许所有触摸事件在 AndEngine 动态壁纸扩展中都不可用?谁知道?如何解决这个问题呢?