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

  • SEARCH
  • Home
  • 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 7523561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:50:19+00:00 2026-05-30T02:50:19+00:00

Im making a program about the game Go and im trying to write some

  • 0

Im making a program about the game Go and im trying to write some code to allow a person to place a bead, which really just shows an invisible bead. But after an hour of going back and forth with it i just cant seem to figure out why the Y coordinate of my motionevent always seems 2 rows down from where it needs to be.

My code for filling my array

for(int y=0; y< 9;y++)
    {
        for(int x=0;x<9;x++)
        {
        String name="Whitebead" + ((9*y)+x+2); //The +2 is because of a naming problem
        WhitePieces[x][y]=(ImageView) findViewById(getResources().getIdentifier(name, "id", getPackageName()));
        }

    }

My code for handling motion events

    @Override
public boolean onTouchEvent(MotionEvent e)
{

         if(e.getAction() == MotionEvent.ACTION_DOWN)
         {
             float X=e.getRawX();
             float Y=e.getRawY();

             if(X>Board.getLeft() && X<Board.getRight())
                 if(Y< Board.getTop() && Y>Board.getBottom());
                    player1.placepiece(X, Y);

         }
         return super.onTouchEvent(e);
}

And finally my code that resolves which bead to what coordinate

    public void placepiece(float X, float Y)
{
    int[] pieceindex=resolvePiece(X,Y);

    pieces[pieceindex[0]][pieceindex[1]].setVisibility(ImageView.VISIBLE);

}


private int[] resolvePiece(float x, float y) {

    int Xindex=0;
    int[] oldcoords= new int[2]; //cordinates are like so {xCoord, Ycoord}
    int[] newcoords= new int[2];
    oldcoords[0]=pieces[0][0].getLeft(); //set the oldcoordinates to the first index
    oldcoords[1]=pieces[0][0].getTop();
    for(int i=1; i<9;i++) //go through the 9 indexs to find the closest X value
    {
        newcoords[0]=pieces[i][0].getLeft();
        newcoords[1]=pieces[i][0].getTop();
        if(Math.abs((int)x-newcoords[0])<Math.abs((int)x-oldcoords[0]))
        {
            Xindex=i;
            oldcoords[0]=newcoords[0];
        }
    }

    int Yindex=0;
    oldcoords[0]=pieces[0][0].getLeft(); //Reset oldcoords again
    oldcoords[1]=pieces[0][0].getTop();
    for(int n=1; n<9;n++) //Go through the 9 indexes for the closest Y value
    {
        newcoords[0]=pieces[0][n].getLeft();
        newcoords[1]=pieces[0][n].getTop();
        if(Math.abs((int)y-newcoords[1])<Math.abs((int)y-oldcoords[1]))
        {
            Yindex=n;   
            oldcoords[1]=newcoords[1];
        }

    }

    int[] rInt= new int[]{Xindex,Yindex};
    return rInt;
}

//////EDIT: Fixed
I figured it out, at the top of the android window is about and inch of space where the title and battery life and stuff go, when you get motion coordinates it takes in the whole screen, where .getTop() only gets from where linear layout Starts. SO instead of using .getTop or.getLeft i used .getLocationInWindow(oldcoord[]) and it places the info i needed into my oldcoord array.

  • 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-30T02:50:20+00:00Added an answer on May 30, 2026 at 2:50 am

    //////EDIT: Fixed I figured it out, at the top of the android window is about and inch of space where the title and battery life and stuff go, when you get motion coordinates it takes in the whole screen, where .getTop() only gets from where linear layout Starts. SO instead of using .getTop or.getLeft i used .getLocationInWindow(oldcoord[]) and it places the info i needed into my oldcoord array.

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

Sidebar

Related Questions

How would a go about making a program where the user enters a string,
I'm making a program which the user build directories (not in windows, in my
I am trying to learn python and am making a program that will output
Well I'm making an program about payrolls and I'm stuck. In the program, after
working on making a flash program that loads about 1000 jpegs and then plays
in my program i have a method which requires about 4 files to be
Whenever I try to write graphical programs (whether a game or really any GUI
I'm making a program and I want to give to the user information about
To learn tkinter I'm making a simple Go game program. I now would like
I need some help making this program for class. We are working with g++

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.