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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:00:28+00:00 2026-05-24T02:00:28+00:00

So imagine a Sims-like 2D game for a touch based mobile phone where one

  • 0

So imagine a Sims-like 2D game for a touch based mobile phone where one can interact with virtually any object in the scene.

How can I efficiently detect which object is being touched by the player?

In my short experience, looping through all the visible objects in the scene and checking if they’re touched has so far done the job, but when there may be many many moving objects in the screen that sounds kind of inefficient isn’t it? Keeping the visible moving objects list can consume time in itself as one may have to loop through all of them each frame.

Other solutions I’ve thought are:

  • Spatial hashing. Divide the screen as a grid and place the visible objects in the corresponding bucket. Detection of the clicked object is fast but there’s additional overhead for placing the objects in the correct bucket each frame.

  • Maintaining a quad-tree. Moving objects have to be rearranged all the time, the previous solution looks better.

What is usually done in this case?

Thx 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-24T02:00:29+00:00Added an answer on May 24, 2026 at 2:00 am

    The first possibility to consider is whether an acceleration method will actually help in your case. E.g., if you only have one query per frame, your current method needs to check each object once. But, if all your objects are moving, almost all acceleration structures need to update each object once — so, in that case, why bother?

    If you determine that an acceleration structure is actually needed, both your solutions seem reasonable:

    • For a touch interface, you know the size of your query. So, if all your objects are the size of a touch or smaller, spatial hashing should be a good solution.
    • if your objects can be large, note that spatial hashing might need to add a large object to many hash buckets. In that case, a quadtree might be a better idea.

    Another solution is to maintain a tree of bounding boxes. There are a variety of algorithms that use this; one in particular is the R-tree.

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

Sidebar

Related Questions

Imagine you want to animate some object on a WinForm. You setup a timer
Imagine an object you are working with has a collection of other objects associated
Imagine the scene, you're updating some legacy Sybase code and come across a cursor.
Imagine I have an function which goes through one million/billion strings and checks smth
Imagine the following scenario. I have a checkbox that the user can check to
Imagine this is my URL NSURL *theURL=[NSURL URLWithString:@http://stackoverflow.com/questions/ask]; How can i extract only: http://stackoverflow.com
Imagine a Model/Collection like: var AModel = Backbone.Model.extend({ defaults: { a: 'a string', b:
imagine a database setup, where x customers can make y orders. normally all customers
Imagine the app is running and you press the iphone button (the phone button)
Imagine an HTML form and the jQuery library is loaded. I'd like it such

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.