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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:20:56+00:00 2026-06-12T12:20:56+00:00

I know there is this question which suggests looping through all canvas elements on

  • 0

I know there is this question which suggests looping through all canvas elements on each mouse move.

However, is there a more effective way than looping through all the elements?

I have quite a few elements on the canvas and looping through them all on each mouse move could be very, very slow.

  • 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-12T12:20:57+00:00Added an answer on June 12, 2026 at 12:20 pm

    Yes, you have to loop through all of your elements.

    That’s how nearly all hit testing/object picking works.

    Now there are a lot of optimizations you can do, like making sure that the mouse coordinate is in the rectangular bounds of the object before you test its real bounds (unless they’re all rectangles, which would make everything convenient and fast, even if there are 10,000 objects). If you have a million objects, you could also split up their location into quadrants, or otherwise add a layer of isolation.

    But at the end of the day you need to loop through every relevant object and ask if its bounds intersect the mouse point. There’s no way of getting around that. It ought to be fast, and if you’ve implemented something that is very slow then you should post it so we can take a look and give you pointers.

    If you need to see a live example I made a simple tutorial on picking and moving shapes in a canvas exactly for explaining situations like this.

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

Sidebar

Related Questions

I know there's no one answer to this question, but I'd like to get
I know there must be a really simple answer to this question, but I
Inspired by this question , I'd like to know whether there is any trick
I know this question has kind-a started religious wars in past and there might
This is a very narrow and specific question, but I know there are someone
i know that there isn't code inside my question, but i think this is
There's already a question on this here. But i want to know if its
I know this is a common question and there are oodles of resources on
I know this is not the only question out there, but I still couldn't
I know this is a simple question for someone out there, but I have

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.