Reputation: 21
I'm creating live wallpaper based on AndEngine Live Wallpaper Extension. In function onCreateScene() I set touch event to my scene. 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:
@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:
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_UP and ACTION_MOVE doesn't work!
Maybe all touch events doesn't available in AndEngine Live Wallpaper Extension? Who know? How to solve this problem?
Upvotes: 1
Views: 582
Reputation: 161
I solve it reimplementing the BaseWallpaperGLEngine class.
In your LiveWallpaperService insert this code:
@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 ;)
Upvotes: 1