我正在基于AndEngine Live Wallpaper Extension创建动态壁纸。 在函数onCreateScene()中,我将touch事件设置为我的场景。这是代码:
@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动态壁纸扩展中没有所有触摸事件?谁知道? 如何解决这个问题?
答案 0 :(得分:1)
我解决了重新实现BaseWallpaperGLEngine类的问题。
在LiveWallpaperService中插入以下代码:
@Override
public Engine onCreateEngine() {
return new LiveWallpaperEngine(this);
}
public class LiveWallpaperEngine extends BaseWallpaperGLEngine {
public LiveWallpaperEngine(IRendererListener pRendererListener) {
super(pRendererListener);
}
@Override
public void onTouchEvent(MotionEvent event) {
mEngine.onTouch(null, MotionEvent.obtain(event));
}
}
@Override
protected void onTap(int pX, int pY) {
}
我希望这可以帮助那些有同样问题的人;)