Jump to content

  • Log In with Google      Sign In   
  • Create Account

Android engine_handle_input


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 invutil   Crossbones+   -  Reputation: 1913

Like
0Likes
Like

Posted 26 March 2013 - 09:31 PM

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;
}

 

 



Sponsor:

#2 invutil   Crossbones+   -  Reputation: 1913

Like
0Likes
Like

Posted 27 March 2013 - 03:41 PM

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;


#3 frob   Moderators   -  Reputation: 22731

Like
0Likes
Like

Posted 27 March 2013 - 04:47 PM

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.


Check out my book, Game Development with Unity, aimed at beginners who want to build fun games fast.

Also check out my personal website at bryanwagstaff.com, where I write about assorted stuff.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS