Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6121715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:48:57+00:00 2026-05-23T15:48:57+00:00

This is something that isn’t specifically game programming stuff, which is why I am

  • 0

This is something that isn’t specifically game programming stuff, which is why I am asking here. Basically, I have this code:

for (int i = 0; i < event.getPointerCount(); i++) {
                switch (event.getAction() & MotionEvent.ACTION_MASK) {
                case MotionEvent.ACTION_DOWN:
                case MotionEvent.ACTION_POINTER_DOWN:
                    if(event.getPointerId(i) == 0)
                    {
                        Log.d("Game", "Primary Down");
                    }
                    else if(event.getPointerId(i) == 1)
                    {
                        Log.d("Game", "Secondary Down");
                    }
                    break;

                case MotionEvent.ACTION_UP:
                case MotionEvent.ACTION_POINTER_UP:
                    if(event.getPointerId(i) == 0)
                    {
                        Log.d("Game", "Primary Up");
                    }
                    else if(event.getPointerId(i) == 1)
                    {
                        Log.d("Game", "Secondary Up");
                    }                      
                    break;  
                }
            }

Which someone else gave me saying that it would fix my original issue which was that if I put down the primary pointer it would be fine, and same for secondary pointer, but whatever the first finger that is released is considered the secondary pointer, but it brings up another issue, which I can’t seem to figure out for some reason. Its kind of early here, so thats contributing, but still.

The issue I ran into with this code was that if the primary and secondary pointers are both down, and either of them are released, it activates both cases, so both “Primary Up” and “Secondary Up” are output, the second one released will recognize which one it is, if both cases go off before I get there, then it wouldn’t matter at that point. Any idea how to fix something like this? Or another way to do the multitouch for a game, or anything for that matter. Thanks!

WWaldo

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:48:57+00:00Added an answer on May 23, 2026 at 3:48 pm

    As far as I know, ACTION_UP and ACTION_POINTER_UP (and the same for XX_DOWN…) only get called once, for each pointer. So you don’t need to do that special treatment, just use event.getX() and event.getY(). To get the corresponding pointerId, you should use

    int index = event.getActionIndex();
    int pointerId = event.getPointerId(index);
    

    The only time I use the for loop is for the ACTION_MOVE event, which is called independently of which pointer moved (and in that case you indeed need to use the pointerId, getX(i) and getY(i) )

    edit : getActionIndex was only added in API 8, so you might want to use

    event.getAction() >> MotionEvent.ACTION_POINTER_INDEX_SHIFT
    

    to get the action index.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is something that I think would be very useful. Basically, I'd like there
This is something that I have never fully grasped in .NET as to the
This is something that I have always wondered about, but never bothered to profile.
So, I know that this isn't something that is normally a good idea for
I have kind of a weird problem .. Something that isn't working on ff
Update: This may be something that just isn't doable. See this TLDR: How do
This is something that I always find a bit hard to explain to others:
This is something that comes up so often I almost stopped thinking about it
This is something that made me doubt for a while so I thought it
This is something that's been bugging me for many years: why most online services

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.