简体   繁体   English

Android ACTION_UP和ACTION_MOVE在动态壁纸AndEngine中不起作用

[英]Android ACTION_UP and ACTION_MOVE doesn't work in live wallpaper AndEngine

I'm creating live wallpaper based on AndEngine Live Wallpaper Extension. 我正在基于AndEngine动态壁纸扩展创建动态壁纸。 In function onCreateScene() I set touch event to my scene. 在函数onCreateScene()中,我将触摸事件设置为场景。 Here is code: 这是代码:

@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);
}

after that I creat onSceneTouchEvent() function: 之后,我创建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;        
}

All is right in this code? 这段代码对吗? Ok. 好。 I'm running it on my phone (Samsung Galaxy S III mini)..., when I touch on screen at first time, in the log is writing: 我正在手机(Samsung 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

when I touch on screen at second time and etc, in the log is writing: 当我第二次触摸屏幕等时,日志中写道:

Logged TouchEvent DOWN        0
Logged TouchEvent DOWN        0
Logged TouchEvent DOWN        0
Logged TouchEvent DOWN        0
.....

...only ACTION_DOWN is detected! ...仅检测到ACTION_DOWN! ACTION_UP and ACTION_MOVE doesn't work! ACTION_UP和ACTION_MOVE不起作用!

Maybe all touch events doesn't available in AndEngine Live Wallpaper Extension? 也许所有触摸事件在AndEngine Live Wallpaper Extension中不可用? Who know? 谁知道? How to solve this problem? 如何解决这个问题呢?

I solve it reimplementing the BaseWallpaperGLEngine class. 我通过重新实现BaseWallpaperGLEngine类来解决该问题。

In your LiveWallpaperService insert this code: 在您的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) {
}

I hope this could help to people with the same issue ;) 我希望这可以对遇到同样问题的人有所帮助;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM