Android engine_handle_input

Started by
1 comment, last by frob 11 years ago

Have I got this code right for pointer up and down events? How do I know if it was a movement rather than up or down?


// http://stackoverflow.com/questions/12500825/android-ndk-multitouch
static int32_t engine_handle_input(struct android_app* app, AInputEvent* event) 
{
    struct engine* engine = (struct engine*)app->userData;
    if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION) 
	{
        //engine->animating = 1;
        //engine->state.x = AMotionEvent_getX(event, 0);
        //engine->state.y = AMotionEvent_getY(event, 0);

		int action = AKeyEvent_getAction(event);

		switch(action)
		{
		case AMOTION_EVENT_ACTION_POINTER_DOWN:
			return 1;
		case AMOTION_EVENT_ACTION_POINTER_UP:
			return 1;
		default:
			break;
		}

        return 1;
    }


    return 0;
}

Advertisement

Found it https://bitbucket.org/runhello/jumpcore/src/2641f6910f3386d74e3401a16a32f4888631cf35/android/jumpcore-eclipse/jni/gl_code.cpp

So it keeps track of all the pointers and it tells me about each one individually using indices?


	unsigned int index = AMotionEvent_getAction(event) & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK;

Keep in mind that these are mutlitouch devices.

There can be many touches simultaneously.

They need to provide an index so you know which of the touches it is telling you about.

The index is stored in the high bits so you will need to shift by AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT to convert the bits into the correct index.

This topic is closed to new replies.

Advertisement