View Full Version : HitTest Generator for Actionscript 2.0

10-23-2009, 03:02 AM
I'll post back with a download and some instructions soon, but for now I'll just give an overview.

I have developed .9 (working on 1.0 now) of a (in my opinion) useful tool for quickly and easily developing accurate hitTests in Actionscript 2.0 without wasting time coding or measuring distances. (Yes, it's only Actionscript 2.0, I haven't upgraded my flash in a while, sorry)

Sure, you can do advanced hitTests by nesting movie clips in a border, or plotting out all the points, but these take TIME! Even the most simple hitTests that involve points are confusing to organize, and leave you frustrated. Now imagine that you could just select the points that you wanted to run a hitTest on, and have it just work. Imagine your code was bundled up into a function you could call whenever you wanted. Imagine all you had to do was tell the application what to do when a hit registered.

Basically, this is how it works.
1. You launch the application (.swf)
2. You import an image of the clip you want to do a hitTest with.
3. You can now move the image around and select points to test against.
4. You click the button "generate".
5. You enter the name of the test (The test is stored as a function), the name of the image you imported, and the name of the clip you want to test against (not the one you imported).
6. HitTest Generator writes the code out for you, which can then be copied and pasted into any flash project.

The project is focused on ease of use and speed (I developed a simple .swf where the user dragged one complex shape around and whenever it hit another, the output box displayed "true", in about 3 minutes total. The code was around 100 lines.)

Once the code is all set up in your application, you can freely scale either clip. Rotation is currently not supported. I'm working on it.

I'll upload the actual program soon, and give some more details about where I'd like to take it, but for the 1.0 release, I'm working on.

- The ability to re-size an imported image.
- The ability to move around the points you want to hitTest against. (Right now, they're displayed in a grid, which can be annoying.)
- A toolset, so you don't accidentally start moving your image around as you're selecting points, or something like that.

The long term goals, if anyone shows an interest in this, are to keep adding a number of customizable features. Doing hitTests on an animation, predicting collisions so your objects don't get embedded into each other, maybe getting into some simple physics, all while maintaining extreme ease of use, cutting down on the time you spend in my program, and ultimately giving the user as much control as possible over the hitTest.

I'm not giving out source code, at least until sometime next year, because I'm developing this for a contest, but I'll make the program freely available.

Anyway, feel free to post back any comments. Is something like this already out there? Would this be useful to anyone? Are there any features you would really like to see implemented? Is this totally useless, and should I give up now? Can you think of other places to display this?

Thanks in advance, hope this helps someone.

10-25-2009, 01:10 AM
Sorry I took so long, the actual application should be uploaded now as an attachment, and here's a quick youtube video I made showing how it's used.


11-05-2009, 08:38 PM
Guess I'll post news here, in case anyone's interested.

I'm in development of version 1.0 right now, I just today actually finished up debugging the code to move points around.

I'll start working on the graphics for the new toolset next, probably. Right now, I just have this red button on the bottom to switch back and forth between selecting points and moving them.

11-20-2009, 10:22 PM
I'm still here, just working on getting the tools set up and drawing some graphics. Sorry for huge delays.

12-09-2009, 01:44 PM
Newest version - I'll upload a new tutorial to YouTube later today.

CHANGES - New Graphics, less crowded, a little more organized. Ability to move around individual points. Everything has it's own tool now, so you shouldn't have that annoying problem where you try and select points and accidentally move your image around.

FORETHCOMING - The next version 1.5 will simply add the ability to scale your imported image. I'll do a little bit more cleaning up for version 2, probably nothing major. Future features I've been looking into are different ways of adding points (now that you can move them, it makes sense to get rid of the grid of points that load right now) and sometime getting into doing a hitTest on an animated movie clip. Far future I'd like to get into automating some simple physics, and making an easy way to set up collisions and reactions to those collisions on tile based games. I'd like to get it to the point where it's automating not just the detection of collisions, but the whole process. Not just, did this object hit?, but what should happen based on how and where it hit?.

Anyway, here's the new file, no instructions, but I'll upload them soon.

And, I hesitate to write it here, but for anyone looking for alternative ways to do hitTests I found this really great actionscript 2.0 class (not made by me) that, (at least now) far surpasses what I've been working on for sheer accuracy.
You can find the link here http://www.gskinner.com/blog/archives/2005/10/source_code_sha.html
I haven't used it, so I can't say anything other than it looks pretty impressive.