Problem with TouchEvent!

  ... discussions about development with the GLES1 branch of AndEngine.

Problem with TouchEvent!

Postby kitty » Sun Jul 17, 2011 1:05 pm

Hi guys!
I'm trying to implement touch feature in live wallpaper, but without success...the touch function is not working :( (Also I tried my test app on device Samsung Galaxy gt 9000..the same problem)

there is my little test app, maybe you guys could see some silly error...

Syntax: [ Download ] [ Hide ]
Using javascript Syntax Highlighting
  1. public class LiveWallpaperTemplate extends BaseLiveWallpaperService implements SharedPreferences.OnSharedPreferenceChangeListener,IOnSceneTouchListener
  2. {
  3.         // ===========================================================
  4.         // Constants
  5.         // ===========================================================
  6.        
  7.         public static final String SHARED_PREFS_NAME = "livewallpapertemplatesettings";
  8.  
  9.         //Camera Constants
  10.         private static final int CAMERA_WIDTH = 480;
  11.         private static final int CAMERA_HEIGHT = 720;
  12.  
  13.         // ===========================================================
  14.         // Fields
  15.         // ===========================================================
  16.        
  17.         //Shared Preferences
  18.         private SharedPreferences mSharedPreferences;
  19.         private Texture mTexture;
  20.         public static TextureRegion mTextureRegion;
  21.         private Sprite mSprite;
  22.        
  23.         // ===========================================================
  24.         // Methods for/from SuperClass/Interfaces
  25.         // ===========================================================
  26.  
  27.         @Override
  28.         public org.anddev.andengine.engine.Engine onLoadEngine()
  29.         {
  30.                 Camera mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
  31.                 final EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.PORTRAIT, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), mCamera);
  32.                 engineOptions.getTouchOptions().setRunOnUpdateThread(true);
  33.                 return new org.anddev.andengine.engine.Engine(engineOptions);
  34.         }
  35.  
  36.         @Override
  37.         public void onLoadResources(){
  38.                 this.mTexture = new Texture(512, 512, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
  39.                 this.mTextureRegion = TextureRegionFactory.createFromAsset(this.mTexture, this, "gfx/big.png", 0, 0);
  40.                 this.mEngine.getTextureManager().loadTexture(this.mTexture);
  41.         }
  42.  
  43.        
  44.         @Override
  45.         public Scene onLoadScene(){
  46.                 final Scene scene = new Scene(1);
  47.                 scene.setOnSceneTouchListener(this);
  48.                 mSprite = new Sprite(100, 100, this.mTextureRegion);
  49.                 scene.attachChild(mSprite);            
  50.                 return scene;
  51.         }
  52.  
  53.        
  54.         @Override
  55.         public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent){      
  56.                 if (pSceneTouchEvent.isActionDown()){
  57.                         mSprite.setPosition(pSceneTouchEvent.getX(), pSceneTouchEvent.getY());
  58.                         Log.d(">>>>>>>>>", "X "+pSceneTouchEvent.getX());
  59.                         Log.d(">>>>>>>>>", "Y "+pSceneTouchEvent.getY());
  60.                         return true;
  61.                 }
  62.                 return false;
  63.         }
  64.  
  65.     * * *
  66. }
  67.  
Parsed in 0.006 seconds, using GeSHi 1.0.8.4
Last edited by kitty on Mon Jul 18, 2011 7:54 pm, edited 1 time in total.
kitty
 
Posts: 34
Joined: Thu May 19, 2011 4:47 pm

Re: Problem with TouchEvent!

Postby Zappescu » Sun Jul 17, 2011 4:46 pm

After "scene.attachChild(mSprite);" add that: scene.registerTouchArea(mSprite).
Zapmobilegames website
Zapmobilegames
Facebook Tic Tank Toe Fans
Tic Tank Toe | Facebook
Tic Tank Toe: a new approach for a classical Game
Image
Zappescu
 
Posts: 105
Joined: Tue May 03, 2011 5:49 pm

Re: Problem with TouchEvent!

Postby kitty » Sun Jul 17, 2011 5:27 pm

thanks Zappescu, but this is not the solution... my goal was to tap on screen and according the touch coordinates place there texture.

it seems, that onSceneTouchEvent is not responding at all!!! also logCat is showing nothing

any idea?
Last edited by kitty on Mon Jul 18, 2011 10:42 am, edited 1 time in total.
kitty
 
Posts: 34
Joined: Thu May 19, 2011 4:47 pm

Re: Problem with TouchEvent!

Postby kitty » Mon Jul 18, 2011 10:27 am

bump
Is really none of you have managed to made live wallpaper with touch function?
kitty
 
Posts: 34
Joined: Thu May 19, 2011 4:47 pm

Re: Problem with TouchEvent!

Postby mdrs » Tue Jul 19, 2011 4:54 am

Try putting an entry in the log outside the if statement. If that fires, you'll know that your conditional isn't testing true.
mdrs
 
Posts: 45
Joined: Mon Mar 07, 2011 10:57 am

Re: Problem with TouchEvent!

Postby kitty » Tue Jul 19, 2011 11:26 am

Hi, mdrs!
I tried your suggestion with this code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. @Override
  2. public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent){  
  3.         if (pSceneTouchEvent.getAction() == MotionEvent.ACTION_DOWN){
  4.                  Log.d(">>>>>>>>>", "down");
  5.         }      
  6.         if (pSceneTouchEvent.getAction() == MotionEvent.ACTION_UP){
  7.                  Log.d(">>>>>>>>>", "up");
  8.         }
  9.         if (pSceneTouchEvent.getAction() == MotionEvent.ACTION_MOVE){
  10.                  Log.d(">>>>>>>>>", "move");
  11.         }
  12.                        
  13.         Log.d(">>>>>>>>>", "touched!");
  14.         return true;
  15. }
  16.  
Parsed in 0.014 seconds, using GeSHi 1.0.8.4


LogCat shows only "touched" and "down" !! no matter if I move, release etc....
Something else important: it works only
1# if live wallpaper is selected... in other words, the button "set wallpaper" is pressed.
2# @Override protected void onTap(final int pX, final int pY){} is disabled!!!
Last edited by kitty on Tue Jul 19, 2011 5:24 pm, edited 1 time in total.
kitty
 
Posts: 34
Joined: Thu May 19, 2011 4:47 pm

Re: Problem with TouchEvent!

Postby mdrs » Tue Jul 19, 2011 3:53 pm

sounds like you need to read up on how the liveDesktop uses touch events. i've never looked into that so i can't help you but that's where i'd start.
mdrs
 
Posts: 45
Joined: Mon Mar 07, 2011 10:57 am

Re: Problem with TouchEvent!

Postby kitty » Thu Jul 21, 2011 4:05 pm

there is some other threads about this problem,...looks like AndEngine has bug in LW service...
so I decided to create my LW without Andengine...sad...
kitty
 
Posts: 34
Joined: Thu May 19, 2011 4:47 pm

Re: Problem with TouchEvent!

Postby jaym » Thu Jul 21, 2011 4:10 pm

I had this terribly annoying problem when I was working on an earlier game. I made a thread about this and my solution was (easy enough) to use a switch statement rather than 'if'. I hope this helps.
AndEngine for Android Game Development Cookbook - Based on AndEngine's latest, greatest, GLES2.0 AnchorCenter branch!
jaym
 
Posts: 690
Joined: Wed May 04, 2011 10:08 pm

Re: Problem with TouchEvent!

Postby drjava72 » Thu Jul 21, 2011 4:28 pm

see method
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. @Override
  2.         protected void onTap(final int pX, final int pY) {             
  3.                 System.out.print("aho vai aho \n");
  4.         }
  5.  
Parsed in 0.010 seconds, using GeSHi 1.0.8.4

It gets called when ever you tap on your wallpaper, drop some icon over it. close some app (pressing home button)

And if you want to put onTouch listener on your sprite

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. mSprite.onAreaTouched(pSceneTouchEvent, pTouchAreaLocalX, pTouchAreaLocalY)
Parsed in 0.010 seconds, using GeSHi 1.0.8.4
Best Regards,
drJava72
drjava72
 
Posts: 287
Joined: Fri Apr 29, 2011 8:03 am

Next

Return to GLES1

Who is online

Users browsing this forum: No registered users and 17 guests