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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:12:42+00:00 2026-05-13T06:12:42+00:00

I wasn’t sure what to call this. I’m building a tile based game where

  • 0

I wasn’t sure what to call this. I’m building a tile based game where the user can click on a tile.
it is a 2d c++ vector of tiles. right now I have an algorithm that positions them like this:

[][][][][][][][][][][]
[][][][][][][][][][][]
[][][][][][][][][][][]
[][][][][][][][][][][]
[][][][][][][][][][][]
[][][][][][][][][][][]

they are positioned based on their size and my tile class holds each of their x and y coordinates, and I have 2 variables for the height and width.

Basically I’d like to find an algorithm that can return the tile my mouse is on based on the mouse’s position.

For example: if my mouse (relative to the game window)’s position is 37,0 and each of my tiles is 10 * 10 in size and they are each tilewidth apart then by having my mouse over 37,0 it should return (4,1) meaning the 4th element on the x and the first element on the y. I thought about doing bounding box checks against each rectangle but I think that will use up too much cpu if i check 60 times / second.

Thanks

  • 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-13T06:12:42+00:00Added an answer on May 13, 2026 at 6:12 am

    If you’re not using an event based environment, you do need to code your own object intersection, mouse detection, etc.

    Here’s the formula in pseudo code for what you want to get:

    tile_width = 10;
    tile_height = 10;
    
    x_tile = Math.ceil(mousex/tile_width);
    y_tile = Math.ceil(mousey/tile_height);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wasn't even sure how to title this right. I have a page that
I wasn't sure how to call this. Basically I have a Label widget. It
Wasn't sure whether this belongs here or on Game Development... Would it be possible
I wasn't really sure if this was the right site to put this question
I wasn't even sure how to phrase this so you'll have to forgive me
I wasn't sure how to phrase this so the title is a bit cryptic.
I wasn't sure what to title this question. Here's my goal: On page one,
I wasn't sure how to word this question, so i'll just explain. I want
I wasn't the one who coded this line of code, and I can't gt
Wasn't sure how to write a good title for this question... :) I'm new

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.