Free ActionScript

Flash AS2 & AS3 Tutorials, Game Code, Effects, Source Files & Sample Downloads

Pixel Perfect Collision Detection

8 Comments »

This is a great “pixel perfect bitmap collision detection with rotation” script by Grant Skinner. This is definitely better than hitTest for rotated irregularly shaped objects and bitmap images. Works great with transparent pngs as well.

Preview

Download Fla Sample

Download Fla Sample

Original Bitmap Collision detection class by Grant Skinner
http://www.gskinner.com/blog/archives/2005/10/source_code_sha.html

Update
AS3 version of this script is available here:
http://www.freeactionscript.com/2011/08/as3-pixel-perfect-collision-detection/

8 Responses

Hey, I made a mouse maze game ages ago, and now I am making the second in the series, and I want to use pixel perfect collision.

I have been working on it for ages using variations on your code, yet I can’t make the collisions work? I want to make it so when the drag object goes over something, it goes to another frame?

Thanks if you could help.

  • Hi Stapled, Unfortunately I don’t have the time to look in to your problem. Please seek help on one of the many flash game development forums listed on the Resources page. Thanks.

  • I asked on the forums on newgrounds, but someone told me to learn more, which I know I need to do. I just don’t know how to go about learning AS, or whether to learn AS2 or AS3?

  • Try these books:
    Essential ActionScript 3.0 by Colin Moock
    ActionScript 3.0 Design Patterns Programming
    ActionScript 3.0 Game Programming University

  • HI pradvan,

    I created a very nice maze, using your script. Thanks for that. Now I encountered a problem with exporting. This movie is loaded into an html file, which shows the movie 100% width and height in the browser window. and now the collision detection doesn’t work anymore… Any idea?

  • Hi wietse,

    Try using noscale:
    Stage.scaleMode=”noScale”;

    If you need it to work while scaled, the script would require changes. If that’s the case, please try seeking help on forums. There are links to some good ones on the resources page.

    Thanks,
    PR

  • Leave a Reply

    You must be logged in to post a comment.