Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 09-17-2011, 07:31 PM   #1
Taufires
Still Flashing
 
Join Date: Feb 2011
Location: Wales, UK
Posts: 86
Default [AS3] Dynamic Collision Detection

Hey All,

So I'm working on a new project that involves some collision detection. I know there's not much information on collision detection through/with classes available. What I'm wondering is which is the best way to detect collisions between two different classes themselves. I know you CANT actually use the hitTestObject method on classes(as I have painstakingly found out).

My scenario is that I have a Bullet that gets fired by the Player that then hits the Enemy and these are all classes. So what would be the best way to detect collisions between the Bullet and Enemy?... so that all instances of the bullet and enemy classes are still detected regardless of when and where they are created as instances within the game.

I know using an Array would be one of the best options, but I don't quite know how I would go about using an Array to do it. Any Ideas?
Taufires is offline   Reply With Quote
Old 09-17-2011, 07:44 PM   #2
Mazoonist
Site Contributor
 
Mazoonist's Avatar
 
Join Date: Jun 2006
Posts: 3,160
Send a message via AIM to Mazoonist
Default

My left-right-shooter game tutorial will probably help you a great deal: http://theflashconnection.com/conten...t-shooter-game

It doesn't use classes, but it does use arrays and loops, and collision detection, and everything is explained every step of the way in detail. Later, if you want, you can create the same or a similar game using classes, but you will probably find that you will usually want to do your collision detection from the "client" object anyway (the object that has actually MADE all the instances of enemies and bullets). Even though my tutorial doesn't use classes "per se," in a way it does, as library symbols are very much like classes, and in fact can be linked to classes.

No, you can't hit test two classes. In fact, you can't program a class to do anything at all (unless it's a static class), you must create objects (or "instances") from those classes. A class is used like a rubber stamp to produce objects, and every object gets its own "copy" of the properties and methods.
__________________
My Tutorials * My Website
Mazoonist is offline   Reply With Quote
Old 09-17-2011, 08:02 PM   #3
Taufires
Still Flashing
 
Join Date: Feb 2011
Location: Wales, UK
Posts: 86
Default

Thanks Maz,

I've actually seen your tutorials before. I'll go over it and see if I can implement it into what I'm doing now. Hopefully I will be able to.
Taufires is offline   Reply With Quote
Old 09-17-2011, 08:24 PM   #4
Mazoonist
Site Contributor
 
Mazoonist's Avatar
 
Join Date: Jun 2006
Posts: 3,160
Send a message via AIM to Mazoonist
Default

Cool! I think the little interactive demo I made on page 3 of that article, which shows how arrays and loops work together, should really help you. I don't get a lot of feedback on it, but I must've made that little thing for somebody!
__________________
My Tutorials * My Website
Mazoonist is offline   Reply With Quote
Old 09-17-2011, 08:38 PM   #5
Taufires
Still Flashing
 
Join Date: Feb 2011
Location: Wales, UK
Posts: 86
Default

Haha, I must say it is one of the better as3 tutorials i've seen. Most just say "here is the code, and it does this", rather than actually explain it. One thing I have to do extra is change the way I create and fire bullets, Ill have to use you Array instead of the way i'm doing it at the moment. I should have it done by tomorrow afternoon.
Taufires is offline   Reply With Quote
Reply


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 10:19 AM.

///
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.