Move an object by touching a screen

Problems with Canvas, OpenGL, etc...

Move an object by touching a screen

Postby majkel » Thu Aug 26, 2010 6:04 am

Im new on this forum, so please dont kick my ass too hard of this problem was solved or explained already. I searched, but I couldnt find it. Uncle google didnt help as well. Maybe I was searching it wrong...
Anyway... I have a small problem with moving an object with a finger on a touch screen. I've created an rectangle, and now I would like to move it according how my fingers move.
My onTouchEvent looks like this
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public boolean onTouchEvent(MotionEvent event) {
  2.                 //
  3.                 float x = event.getX();
  4.         float y = event.getY();
  5.         float z = 1.0f;
  9.         if(event.getAction() == MotionEvent.ACTION_MOVE) {
  11.                 float dx = x;
  12.                 float dy = y;
  13.                 float dz = z;
  14.                 xPaddle = dx;
  15.                 yPaddle = dy;
Parsed in 0.017 seconds, using GeSHi

and Im using xPaddle and yPaddle to move my object by
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void onDrawFrame(GL10 gl) {
  3. .
  4. .
  5. .
  6. gl.glTranslatef(xPaddle, yPaddle, 1.0f);
  7.                 paddle.draw(gl, 1);
  8. }
Parsed in 0.013 seconds, using GeSHi

but it doesnt want to listen to my fingers. It responds to the touch and moves somewhere.. but not under my finger.

Do you guys know if im on the right track? By looking at the code, can you suggest any solutions or point me to a source where this is well explained? I would really appreciate some help :)

Once Poster
Once Poster
Posts: 1
Joined: Thu Aug 26, 2010 5:51 am


Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 2 guests