Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 10-17-2009, 03:26 PM   #1
Join Date: Feb 2009
Posts: 83
Default [AS3] Collision Map

I was wondering if anyone had any pointers on how to create some sort of collision map in ActionScript? Like a picture that has areas that are either transparent or black, if you are colliding with the black area, that means you are out of bounds, while you may traverse freely on the transparent areas.

Trying to figure out a quick and easy way to add boundaries to a top-down map that I've created randomly in Photoshop.
Ciubhran is offline   Reply With Quote
Old 10-17-2009, 04:48 PM   #2
Salmon Eater
TomMalufe's Avatar
Join Date: Jun 2007
Location: Doylestown, PA, USA.
Posts: 740

There are a few tutorials that you should be able to find easilly enough on how to do "pixel hit tests" with bitmaps.

Here is one of them that I found right away by searching google for "as3 bitmap collision detection"

I've seen others as well that are better written then this one, but do pretty much the same thing.
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." -- Chinese Proverb.
TomMalufe is offline   Reply With Quote
Old 10-17-2009, 10:05 PM   #3
Join Date: Feb 2009
Posts: 83

Thanks for the reply.

Even though I didnt read the tutorial I think I did somewhat what the person did in that tutorial.

I just constantly check the units coordinates against the collision map. If the pixel I am standing on (on the collision map, has a color (getPixel result value) larger than 0, then I am on unwalkable terrain. Walks like a charm!

Having a bit of problem now with my AI though, can't really collision detect the same way. It still works, it just sometimes cowers and runs back to its original position (which it should do when it doesnt have a "scent" on the player unit and the player unit is out of range/out of sight.

But still, the collision map/pixel test really did the job for me, perfect wall-collision detection for my player unit.
Ciubhran is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 06:32 PM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.