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 8435659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:58:25+00:00 2026-06-10T06:58:25+00:00

I have a class that is meant to be a very simple in-game level

  • 0

I have a class that is meant to be a very simple in-game level editor for a 2D game composed of tiled image under Sprites. The purpose of the code I am debugging is to update a char within a StringBuffer based on where the user clicks in order to change what tile is displayed in the position the clicked.

The String Buffer being modified is used by the program as a map to identify which images should be drawn at which tile. Each char value used in the Buffer will represent 1 tile, with the value of the char deciding which image is displayed there. To this end I have defined a constant integer (public static final int TILE_SIZE) to 40. My tiles are all squares with a size of 40 by 40 pixels, so this constant is used to help calculate anything that needs to be adjusted by the image’s width and height.

The problem is this: whenever the user clicks on the screen, the x and y value of the mouse passed to the method that updates my StringBuffer are divided by 40 before any code in the method executes.

Here is the relevant code:

    private void modifyGeometry(int x, int y, char tile){
        //Levels are 20x20 grids
        int xIndex=x;//The value of the index we will read based on x
        int yIndex=y;//The value of the index we will read based on y

        if(x<21*TILE_SIZE && y<21*TILE_SIZE){//For safety reasons, check that the x and y aren't somehow greater than the screen

        xIndex=xIndex/TILE_SIZE;//Factor x down to which tile in the row it is on

        yIndex=yIndex/TILE_SIZE;//Factor y down to which tile in the column it is on

        if(xIndex>19){//We will need to reduce the value of x if its factor based on the TILE_SIZE is greater than 19 (a row is 0-19)
            int storetemp=xIndex/20;
            xIndex=xIndex-(20*storetemp);//Because xIndex is an int, xIndex/20*20 does not come out to xIndex, but instead only the first digit of xIndex (0-9)
        }

        if(y>19){
            int storetemp=yIndex/20;
            yIndex=yIndex-(20*storetemp);
        }
    }

    int index=xIndex+yIndex;
    this.geometry.setCharAt(index, tile);//This will set the character corresponding to the point the player clicked to the tile selected
    }

…

private class MouseInput extends MouseAdapter{
    public void mouseClicked(MouseEvent e){
        if(layer==0){
            modifyGeometry(e.getX(),e.getY(),currentTile);
        }

I have used some break points in Eclipse’s debugger to determine that e.getX() and e.getY() are getting the coordinates right (I had little doubt of that), but before int xIndex=x even goes through, both x and y have been divided by the constant (40). No method I wrote is called in between the variables being passed and the method receiving them.

  • 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-06-10T06:58:26+00:00Added an answer on June 10, 2026 at 6:58 am

    I very much doubt that anything magical is going on here. Options:

    • Your diagnostics are wrong
    • You’re not actually running the code you think you’re running, e.g. due to the build getting out of date
    • If you’re using AOP or something else which modifies bytecode, that could have an effect

    I’d add some logging instead of relying on the debugger. For example:

    private class MouseInput extends MouseAdapter{
        public void mouseClicked(MouseEvent e){
            if(layer==0){
                int x = e.getX();
                int y = e.getY();
                log.info("About to modify geometry; x=" + x + "; y=" + y);
                modifyGeometry(x, y, currentTile);
            }
        }
    }
    

    And:

    private void modifyGeometry(int x, int y, char tile) {
        log.info("Within modifyGeometry; x=" + x + "; y="+ y);
        ...
    }
    

    I’d be amazed to find those log lines show different values.

    I’d also add that the business about further dividing by 20 is extremely confusing, and suggests that actually you should be able to simplify your design significantly.

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

Sidebar

Related Questions

I have a very simple class: People: class People { private string LastName =
I have a very simple object models. public class Contact { public virtual int
I have an (apparently) very simple class initialization, with two constructors, and when I
Let's assume we have this very simple table: |class |student| --------------- Math Alice Math
what i mean by that is: i have a class called Customer: public class
I have class that extend FragmentActivity in it I add fragment to layout as
I have class that looks like this: class A { public: class variables_map vm
I have class that represents users. Users are divided into two groups with different
I have class grades that I need to check if a specific grade is
I have class A such that: class A { static int i; A(); f1();

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.