Understanding Max2D Collision Functions

BlitzMax Forums/BlitzMax Tutorials/Understanding Max2D Collision Functions

assari(Posted 2006) [#1]
If you've been wondering how to use the Max2D collision functions, here's a good opportunity to learn. This tutorial covers all four Max2D functions; ImagesCollide, ImagesCollide2, CollideImage and CollideRect.

The tutorial is broken into 3 Parts:-
Max 2D Collision Part 1
Max 2D Collision Part 2
Max 2D Collision Part 3

This is actually part of my Learning 2D Game Programming Series.


bradford6(Posted 2006) [#2]
Excellent! great work assari

(I also like the way the images load from your web page!)


hub(Posted 2006) [#3]
very usefull. Many thanks !


GW(Posted 2006) [#4]
Very nice.
I'm curious about why you pass images into a bank before loading them?


ImaginaryHuman(Posted 2006) [#5]
Neat, thanks for the tuts.


tonyg(Posted 2006) [#6]
Superb as always. Just checking the first and you have a slight error when suggesting ImagesCollide2.
If ImagesCollide(Alien,150,200,Frame,0,AlienSize,AlienSizePlayer,MouseX(),MouseY(),0,0,PlayerSize,PlayerSize)

should be...
 If ImagesCollide2(Alien,150,200,Frame,0,AlienSize,AlienSize,Player,MouseX(),MouseY(),0,0,PlayerSize,PlayerSize)

(notice the function and 'aliensizeplayer' with the comma).
<edit> to take out rambling.


assari(Posted 2006) [#7]
tonyg, well spotted. Thanks. It's now corrected.

@GW, when you loadimage from http::, you need to loadbank first otherwise the loadimage fails


GW(Posted 2006) [#8]
Interesting.. That's good to know.


simi(Posted 2006) [#9]
I've released a german translation.

=> http://simi.chat-blitz.de/tut_collision/

___________________________________________

Thread in the german forum:

=> http://www.blitzforum.de/forum/viewtopic.php?t=18500


Diordna(Posted 2006) [#10]
The function CircRectsOverlap function is structured badly. In the function name, Circ comes first, but in the parameters, Rect comes first.

Confoozling.


NoBoDo(Posted 2006) [#11]
Great job on the tutorial.

However, the ImagesCollide / ImagesCollide2 code on the page still has the error mentioned above:

If ImagesCollide(Alien,150,200,Frame,0,AlienSize,AlienSize,Player,MouseX(),MouseY(),0,0,PlayerSize,PlayerSize)


There is another error on that same line - it has the Y component of the alien's position off by 100 pixels, so the collision is happening well away from where it should.


assari(Posted 2006) [#12]
NoBoDo, thanks for letting me the know the errors. They are fixed now.

Also noticed a bug in the exit condition, fixed that too :)


Matt Merkulov(Posted 2007) [#13]
Here's russified version translated by JohnK:
http://blitzetc.boolean.name/articles/coll1.htm
http://blitzetc.boolean.name/articles/coll2.htm
http://blitzetc.boolean.name/articles/coll3.htm