1. Senior Member
Join Date
Mar 2013
Location
Greece
Posts
174
Rep Power
5

Hello Guys... i Hope this time i make the post in the right section :P
i need to know if there are more advances ways to chech about the collision between two bufferedImages For example.... in my project to chech about the Collision i use the ordinary way with creating two Rectangles and then just check if one intersect in other..

but there are some problems one like this :

by Creating two Rectangles is really hard to understand from what side the images collides
then i try to Create a 2D line for each side (Left , Right , up ,down) then to check which one of the collides first then do what i want.. but if you chech the image above what will happen if the image collides with the up left corner ? it depends of that line will collide first..

to solve this problem (with my low knowledge) i do something like that :

but this is very bad idea.. i have a lot of enemies characters.. so this is very confusing...

then i read something about Per Pixel based collision detection and XNA but i don't really understand what is going on.. so i need help .. :P
every info will be useful ;)

2. Just a guy
Join Date
Jun 2013
Location
Netherlands
Posts
5,114
Rep Power
9

## Re: More Advances Collision detection

The way I deal with the bounding box problem is to add pixel perfect collision detection. So collision detection is a two-phase check:

1) do the bounding boxes overlap?
2) when they do, do any actual pixels of the entities overlap?

Step 2 is the one that makes programming difficult, how the heck do you do that?

I did it by creating a dumb array of booleans for each frame of each bob (bob = an animating sprite) where each index represents a single pixel in the image; it would be true if the pixel is opaque and false if it is transparent. Then all I needed to do was compare the parts of the array where the bounding boxes overlap (again: very much not easy) to see if one of the cells that are on top of each other both contain the value true. If so: DEATH!

EDIT: eh its a bit confusing what you're after actually. You are also talking about a direction. But depending on the location of the pixels that touch each other, you should be able to work out a rudimentary collision location too. I take it you want to be able to check if it is death for you or death for the enemy because you jumped on its head :)
Last edited by gimbal2; 08-19-2013 at 02:31 PM.

3. Senior Member
Join Date
Mar 2013
Location
Greece
Posts
174
Rep Power
5

## Re: More Advances Collision detection

Remarkable Answer... Thanks for the informations!! i am going to take a look at them right now ;)

Google is my best friend ;)

4. Just a guy
Join Date
Jun 2013
Location
Netherlands
Posts
5,114
Rep Power
9

## Re: More Advances Collision detection

yeah well in this case not too much, this is something that basically everyone reinvents for himself :)

Did I ever point you to java-gaming.org? Its a website where basically all Java developers that do game development congregate (some even that SELL games they build using Java, which is quite an amazing achievement). There you can find tons and tons of questions and examples on doing not only collision detection but basically everything else too. You probably know Minecraft? It basically started there. You can still find the old thread where Notch was sharing his ideas and was asking for advice.

5. Senior Member
Join Date
Mar 2013
Location
Greece
Posts
174
Rep Power
5

## Re: More Advances Collision detection

Yeah i know about Minecraft ... i have spend a lot of times playing it :P hahaha
Thx for the website i am going to check it right now :P

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•