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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:22:58+00:00 2026-05-24T19:22:58+00:00

I’m programming a 2D tile based game in Java like Bomberman (my first game).

  • 0

I’m programming a 2D tile based game in Java like Bomberman (my first game).

I use a 2D array to represent the map where I keep track of walls, walkable spaces, etc. By now I was able to make the player move smoothly swaping sprites depending on the direction key he presses (but not interacting with the background/map, it can walk randomly and get out of the screen).

My problem comes when I want to keep track of the player’s position in the array. Logically the character always belongs to only one tile but graphically it can be between two tiles. How can I solve this issue?

I already tried this:

currentTileArrayX = x / tileWidth;

currentTileArrayY = y / tileHeight;

Where x and y are the top-left coordinates of the sprite.
But everything became very buggy because the player’s sprites aren’t the same size as the tiles.

I had another option in mind that would solve the previous problem: When the player presses a direciton key, move the character to the next tile like an animation. This wouldn’t let the player stop in the middle of two tiles… But what if he interrupts it with another key press? How can I stop user’s action while the animation is executing? I think this is the easiest solution but I don’t know how to implement it.

I already tried to find the solution in other questions but I had no luck. I hope you can help me.

Thanks a lot.

  • 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-24T19:22:58+00:00Added an answer on May 24, 2026 at 7:22 pm

    Aaaaaaaaaaaaaaah! Encountering the ‘discrete space problem’ 🙂 Your logic map is discrete but your UI movements are in the continuous space. I don’t the user can actually be in both tiles “at the same time” – visually yes, but never ‘internally’. Now you are getting the position of the player and that can be “anywhere” within the tile or “on the boundary” of 2 tiles so to speak…

    You have two solutions to this problem, IMO:

    1. Use simple rounding: If the player position is < tile-boundary just keep him on the previous tile. If Greater on the next. Now the problem of boundary – you can use a heuristic, since you shouldn’t trust the accuracy of the floating point comparisons (i.e, comparing to 0 is not a good thing to do). So you can try something like this if(currentPosition - boundary <= 0.000000001) then assume it’s the next tile else stay on the same one.
    2. Well @Jay beat me to it. So the second one is to actually have a
      movement speed defined and move the character that many steps per
      ‘click’/’button press’ – but you say you have the problem of key
      pressed in “between”. I’m guessing if you code is designed like this
      then it shouldn’t be a problem:
        update()
            {
               calculate(); //update all datastructures/calculations
               draw(); //update the visual representation based on calculations
            }
    

    update() is a.k.a, gameLoop. I think this should solve your problem…

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

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.