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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:26:52+00:00 2026-06-09T11:26:52+00:00

So I decided to look up some collision detection but I’ve been having trouble

  • 0

So I decided to look up some collision detection but I’ve been having trouble finding proper information
regarding 2d collision detection between two images that includes how to properly avoid detecting the transparent
areas of an image but I did find one post which I got myself attached to but the problem is that I don’t
really understand the post nor do I understand why he does some of those things…

Here’s the post in question: https://stackoverflow.com/posts/336615/revisions

So first of all I want to ask if this solution is actually a good one / proper or if I should just look elsewhere.

Secondly I wonder, in his post, he mentions using integer arrays, not 2d arrays either it seems, to
set 1 and 0 to decide whether or not the pixel is transparent or not but I don’t really know how I am supposed
to achieve this. At first I thought it could be achieved by just forming a string of 1 and 0s and convert it to a Long
but even with a mere image width of 25, the Long, gets… too long…

I also tried this with no luck, since the code does not function with this array:

 long[] array = new long[30*30]; // height * width of the image
    int x = 0;
    int y = 0;

for(int i = 0; i<30*30; i++){
    if(image.getRGB(x,y) == 0){
         array[i] = 0;
    }
    else{ array[i] = 1; }

    x++;
    if (x==30){
         y++;
         x=0;
    } 
}

Thirdly, I was hoping someone could maybe explain the whole process and why the things he does, are necessary.
By the way, I do know how those bit wise operators work!
In other words, I don’t understand his train of thought / motivation for doing the all things in the code and I would like to gain an understanding of all this!

I don’t really know how to proceed right now hehe…

  • 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-09T11:26:54+00:00Added an answer on June 9, 2026 at 11:26 am

    The result of the bitwise AND operation (&) is true (1) for each each bit where the the corresponding bit is true in both operands, and false (0) otherwise.

    The idea he’s using is to create a version of the image (a mask) where each non-transparent pixel in the original image is stored as a ‘1’ bit, and each transparent pixel as a ‘0’ bit. These are packed into a single integer, which can be tested against the mask for another image with a single AND operation (before the AND he calculates the horizontal distance between the two images and shifts one of the masks if necessary).

    For example, let’s assume that we have the following two 4×1 pixel images:

    5, 0, 0, 5
          8, 8, 8, 8
    

    Although I placed them on separate rows here for practical purposes, you should view them as being on the same row, so the last two pixels of the left image overlap with the first two of the right image.

    The masks for the rows when viewed in binary representation would be:

    1001
    1111
    

    The distance between the left and right image is -2, so we shift the first mask left by 2 bits:

    1001 << 2 => 100100
    

    So now we have these masks:

    100100
    001111
    

    ANDing these gives us:

    000100
    

    The non-zero result tells us that we have a collision.

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

Sidebar

Related Questions

I decided to look a good tileset to use and found some, but the
Hello everyone I been trying get php uploader working but having a lot of
We decided to use mongodb for some web application (instead of mysql) but want
Been playing with Ruby on Rails for awhile and decided to take a look
I'm newbie to mvc, do decided to look through some site examples. Started from
So, I decided to look back at some data structures to keep myself sharp
I'm trying to cleanup some URLs on my blog, so I've decided to look
I have decided to have a look at JSP technology and some of the
I needed some really simple XML output so I decided to write my own
Lately i decided to take a look at Java so i am still pretty

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.