This post is a portion of Part 12 in my on going series about 2D Game Development using the Allegro 5 library. These posts are in course order. You can see all of the posts in this course by clicking the “2D Game Development” button at the top of this site.
- 12.0 – Collision Detection
- 12.1 – Bounding Rectangle Collision Detection
- 12.2 – Distance Based Collision Detection
- 12.3 – Pixel Perfect Collision Detection
Full source can be found here.

It took 11.5 seconds for me to load on a 1.4 GHz PC, so the result will vary for every computer. Just a little something to keep in mind for everyone. =)
Yes, it is certainly not optimized.
Mask_New() would probably be *much* faster if you ran al_lock_bitmap(bmp) before the for-loop and al_unlock_bitmap(bmp) afterwards.
Agreed. Locking would definitely optimize this library
For ball2.image i set a realy big png with transparent center.
(I want it would work like a map background with trasnparent center.)
But somehow i believe when i set the mask: ball2.mask = Mask_New(ball2.image);
it aligns it to middle of the image.
So the collision and mask draw is not currently aligned with the image x y.
al_draw_bitmap(ball2.image, 0, 0, 0);
Mask_Draw(ball2.mask, ball2.x, ball2.y);
it looks like this: http://s16.postimage.org/8ggrk2bqt/asd.jpg
;D
So I want to know where to change in the PPCD.cpp so it would align mask normaly by x and y.
I tried to compile this on Ubuntu 11.10 and give me this error
/tmp/cccJve2m.o: In function `Mask_Create(int, int)’:
PPCD.cpp:(.text+0×195): undefined reference to `operator new(unsigned int)’
PPCD.cpp:(.text+0x1bb): undefined reference to `operator new[](unsigned int)’
/tmp/cccJve2m.o: In function `Mask_Delete(mask*)’:
PPCD.cpp:(.text+0x2ce): undefined reference to `operator delete[](void*)’
PPCD.cpp:(.text+0x2df): undefined reference to `operator delete(void*)’
collect2: ld devolvió el estado de salida 1