Touchscreen Input

Put your problem here if it does not fit any of the other categories.

Touchscreen Input

Postby Roarke » Sun Mar 01, 2009 6:36 am

Hi guys! Finally writing my first Android program.

I've searched around and looked and looked and I can't seem to find a tutorial or even code to get the input coords for the touchscreen.

Like when some games place some item right under your finger (airhockey?)
but I only really need the X value.
Need it to be efficient, and also to detect when the user lifts the finger.

Right now I'm just trying to make a green block move across the screen with the finger.
I took the 2d tutorial http://www.anddev.org/2d_tutorial-t3120.html
made the box not move automatically and I want to tie it to a finger but I can't find a way to do that.

I read about the GestureDetector, but I can't find a way to get the X coordinant from it.
I also read that the GestureDetector can be slow in gaming applications, which is what I'm intending to come out with :)

Any help would greatly be appreciated.

Thanks,
Roarke
Roarke
Freshman
Freshman
 
Posts: 4
Joined: Fri Oct 31, 2008 2:29 am
Location: Vancouver WA

Top

Postby mortefer » Sun Mar 01, 2009 10:16 pm

In your view (or even activity) try adding:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.         public boolean onTouchEvent(MotionEvent e) {
  3.  
  4.                 int x;
  5.  
  6.                 if(e.getAction() == MotionEvent.ACTION_DOWN) {
  7.  
  8.                         //figer is down on the surface
  9.  
  10.                         x = e.getX();
  11.  
  12.                 }
  13.  
  14.                 if(e.getAction() == MotionEvent.ACTION_MOVE) {
  15.  
  16.                         //figer is moving
  17.  
  18.                         x = e.getX();
  19.  
  20.                 }
  21.  
  22.                 if(e.getAction() == MotionEvent.ACTION_UP) {
  23.  
  24.                         //figer is up
  25.  
  26.                         x = e.getX();
  27.  
  28.                 }
  29.  
  30.                 return true;
  31.  
  32.         }
  33.  
  34.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
mortefer
Experienced Developer
Experienced Developer
 
Posts: 54
Joined: Sat Dec 20, 2008 11:24 am

Postby Roarke » Mon Mar 02, 2009 8:18 am

Thank you! That was awesome!

Worked great!

Now I've got other problems, but I'm going to try and figure it out before posting :)

Peace to all,
R
Roarke
Freshman
Freshman
 
Posts: 4
Joined: Fri Oct 31, 2008 2:29 am
Location: Vancouver WA

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 15 guests