View Full Version : Games hitTest

03-13-2001, 03:53 PM
I forum, is my first time here!
I found around the web a lot of nice platform game and I like to realize one. I read the tutorials about hitTest, but the thing works when there are only two objects. I mean in platform games there's the HERO that jump from a platform to another and so on. I suppose that the platforms are all instance of the same MC, so where I have to put the code that detect collision? Have u a tutorial to suggest me?
Thanks a lot
Brid :)

03-18-2001, 11:04 AM
The following code will first duplicate an MC four times at predetermined positions on our screen. Then we will test for hit tests on the MC's:

1) Frame 1:

xpos = 10;
xspace = 100;
for (i=1; i<=4; i++) {
platform.duplicateMovieClip("platform"+i, i);
this["platform"+i]._x = xpos;
xpos += xspace;

This is where we duplicate the 'platform' MC four times, placing each additional duplicated MC 100 pixels to the right. For more precise positioning target each dup MC individually:


2) Place this on the 'hero' MC:

onClipEvent (enterFrame) {
if (this.hitTest(_root.platform)||this.hitTest(_root. platform1)||this.hitTest(_root.platform2)||this.hi tTest(_root.platform3)||this.hitTest(_root.platfor m4)) {
_root.result = "Hit!";
} else {
_root.result = "Miss";

This tests for a hit test on all five MC's and then outputs the results to a dynamic textfield on our stage named 'result'.

Best of luck.


03-19-2001, 08:34 PM
Hi Marx,
I found your suggest really usefull. Thanks a lot :D
Bye brid