This content has been marked as final. Show 7 replies
that's very inefficient coding (you'll find) if you try and detect collisions among several movieclips. skinner has a superior method which is much more efficient if you're using flash 8:
Very cool, I got that working, thanks. But I would still like to figure out how to get the way I was trying to do it to work. This way might be more effective for another part of the game, plus this is for a class, and I'm not sure if my teacher will allow me to use that (since it may be considered plagiarism, even though the author says it can be distributed freely).
to use the sentry technique you need to position sentry movieclips along the perimeter of the road along which your car is going to travel.
you have a library movieclip (road_mc) and it has sentry movieclips but that movieclip is not given an instance name (and, in particular, is not _root.road_mc) on the _root timeline.
Oh wow, I can't believe I missed that. There's still a problem though. It only works with the first empty movie clip I put in the road_mc movie clip. I tried a few things to make it work, but no success. My guess is that the for in loop isn't looping (and if it is, it's looping on the same movie clip).
I updated the file from my first post.
no, it's looping through all the sentry movieclips. it's just that your setting the _alpha of the car to 50 and then to 100 on every loop except when the last sentry evaluated has a positive hitTest(). then you're setting the _alpha to 100 and then to 50.
(learn to use the trace() function. it's very helpful when debugging.)
to remedy you should break out of your for-loop when you have a positive hitTest(). use:
Wow, how strange. I wouldn't have expected to have to break out of an if statement. Anyway, thanks for all the help.
you're breaking out of the for-loop with that code. it might be easier to see the problem is you use a variable to designate if there is any positive hitTest between the car and a sentry.
you would set the variable to false prior to entering the for-loop and then change it to true if there is any postive hitTest(). (do not change it to false if you have a false hitTest().) then at the end of the for-loop if the variable is positive, you can conclude the car has hit, at least, one sentry. if it's negative you can conclude the car has hit no sentries.