Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: OpenGL Android
Hi there,

I'm now trying to mastering OpenGL for mobile gaming, so I'll need to ask a boxes of question about it. Here's my current problem now.

Specification :
- android SDK API 6 (android 2.1)
- using command line to create new project, build, and install
- using emulator (AVD) to run program
- Windows 7 Pro SP 1 32x

I'm trying to rotate triangle in my android on touch (onTouchEvent).
Here's my code snippet :
package .....;
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
public class segitiga extends Activity{
class HelloOpenGLES10SurfaceView extends GLSurfaceView {
public HelloOpenGLES10SurfaceView(Context context){
    public boolean onTouchEvent(MotionEvent e) {
    float x = e.getX();
    float y = e.getY();
    switch (e.getAction()) {
        case MotionEvent.ACTION_MOVE:
            float dx = x - mPreviousX;
            float dy = y - mPreviousY;
            // reverse direction of rotation above the mid-line
            if (y &gt; getHeight() / 2) {
              dx = dx * -1 ;
            // reverse direction of rotation to left of the mid-line
            if (x &lt; getWidth() / 2) {
              dy = dy * -1 ;
            mRenderer.mAngle += (dx + dy) * TOUCH_SCALE_FACTOR;
    mPreviousX = x;
    mPreviousY = y;
    return true;

The porblem is when I tried to compile (install debug / adb installd ) to my emulator it's throw me error like this on the line of :
public boolean onTouchEvent(MotionEvent e)

It need ";" after onTouchEvent and after "e". So it should be this like according to the compiler :
public boolean onTouchEvent;(MotionEvent e;)

And that's wrong things.
How should I fixe it?

Thanks in advances
Posted 25-Apr-12 18:08pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

It looks like you are nesting the functions. onTouchEvent() is placed within the function HelloOpenGLES10SurfaceView(). It needs to be placed in a class directly, either the main class, or a nested class.
satrio_budidharmawan at 26-Apr-12 5:05am
But it's should be there I thought.
Because its GLSurfaceView's member, if I moved it out, it wont even know requestRender() and some things.
Niklas Lindquist at 26-Apr-12 5:11am
In that case, place it outside of HelloOpenGLES10SurfaceView's constructor.
satrio_budidharmawan at 26-Apr-12 5:14am
So its classless?
satrio_budidharmawan at 26-Apr-12 5:16am
But somehow I tried to separate it onto 3 different files : main, view, and renderer.
And it works like charms, but I still wanted to know what's wrong with my previous version
Niklas Lindquist at 26-Apr-12 5:34am
It's not "classless". It should look like:
class HelloOpenGLES10SurfaceView extends GLSurfaceView {
public HelloOpenGLES10SurfaceView(Context context){
} // end construtor
public boolean onTouchEvent(MotionEvent e) {
} // End class
satrio_budidharmawan at 26-Apr-12 5:39am
mRenderer = new HelloOpenGLES10Renderer();
underneath public HelloOpenGLES10SurfaceView(Context context){...}
would be unknown I thought,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 455
1 Sergey Alexandrovich Kryukov 445
2 Maciej Los 290
3 ProgramFOX 275
4 CHill60 225
0 OriginalGriff 550
1 Sergey Alexandrovich Kryukov 470
2 Maciej Los 310
3 ProgramFOX 275
4 Peter Leow 250

Advertise | Privacy | Mobile
Web03 | 2.8.150331.1 | Last Updated 26 Apr 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100