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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:32:58+00:00 2026-06-08T15:32:58+00:00

UPDATE: I found this enormously helpful article explaining canvas per-pixel collision detection. I’m working

  • 0

UPDATE: I found this enormously helpful article explaining canvas per-pixel collision detection.

I’m working on a collision system for a javascript game using HTML5 canvas. Each object has an image as a sprite and when a non-transparent pixel of any one object overlaps another, the collision code is triggered. But before anything else the objects need to be moved so that they are just touching each other and no longer triggering a collision. I need help calculating the overlap of any two objects in terms of x and y in order to move one accordingly. Here’s what we know:

  • The coordinates of the collision point relative to each object
  • The positions of the objects (and therefore the distance between them)
  • The width and height of the objects
  • The velocity of the objects in the x and y directions (a vector)

Another note: the images for these objects are uneven shapes, no perfect circles, but the radius from the center to the collision point can be calculated.

EDIT: I haven’t seen a lot of response, so I’ll be more specific. In the image below, two objects are colliding. The overlap area is in red. How would you go about finding the lengths of the green lines?
enter image description here

  • 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-08T15:33:02+00:00Added an answer on June 8, 2026 at 3:33 pm

    I’m honestly clueless about HTML 5 and how you can make games in pure HTML 5. But you would also need to know a velocity (IE, their direction. This way you can send them backwards from where they came)

    If it was in a standard programming language, one method would be to use a while loop (moving the sprite back until the collision == false). Another method would be a more complicated calculation of how far the intersection is and subtract individual x and y values so they are not collided.

    EDIT:
    Then the easiest way is like I said, to put the object thats moving in a while loop that moves it backwards 1 pixel in each axis until its collision tests false. Example:

        int x1 = 500; //x location on screen
        int y2 = 500; //y location
    
        public boolean fixOffSetX(Sprite s) {
             int x2 = s.getX();
             int y2 = s.getY();
    
             //not writing the whole thing
             //enter a while loop until its not colliding anymore
    
             while(collision is still true) {
                x--;  or x++; 
    
                //depending on direction 
                //(which is why you need to know velocity/direction of your sprites)
                //do the same for the Y axis. 
            }
        }
    
    
        //This method will return if the 2 sprites collided, you do this one
        public boolean collisionTest(Sprite s1, Sprite s2) {}
    

    You should look at doing very basic collisions, since it is a VERY complicated part of programming

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

Sidebar

Related Questions

I found this article about how to insert, update and delete using linq pad
I'm working on processing a large csv file and I found this article about
using Microsoft.SqlServer.Management.SqlStudio.Explorer; unable to find this pls assist [update] found the dll's in this
Update : I found almost exact similar question , yet it has slightly different
Update Solution Found See Bottom of post if interested Seems simple enough and for
12:18:55,541 INFO [UpdateChecker] New update(s) found: 2.0.0 [ http://ehcache.org/news.html] How do I suppress ehcache
[Update: I've found the API reference. The method used is below] <?php wp_delete_post( $postid,
Possible Duplicate: SQL ORDER BY total within GROUP BY UPDATE: I've found my solution,
I found something that works with updating one field at here: http://www.karlrixon.co.uk/articles/sql/update-multiple-rows-with-different-values-and-a-single-sql-query/ UPDATE person
I found some problem. When i running apc_store and more times update a page

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.