Home  |  About  | Last |  Submit  |  Contact
AllQuests.com



Previous Question:  wicked filter effect explanation  ActionScript 3.0Next Question:  Unsigned int fun  ActionScript 3.0
Question Collision Detection with AS3 ( kirupaForum ActionScript 3.0 )
Updated: 2008-04-13 11:38:33 (6)
Collision Detection with AS3

I have looked around, but can't find any good examples on collision detection with AS3 :/. So that is why I am here with you smart people. I have a game that was built in AS2 that I now want to convert to AS3, but one major hurdle is the collision detection. This is what I had before:

ActionScript Code:
var flag:Boolean = false;
  if(mc.hit.hitTest(rocket_mc.getBounds(_root).xMax, rocket_mc._y, true)) { flag = true; }
  if(mc.hit.hitTest(rocket_mc.getBounds(_root).xMin, rocket_mc._y, true)) { flag = true; }
  if(mc.hit.hitTest(rocket_mc._x, rocket_mc.getBounds(_root).yMax, true)) { flag = true; }
  if(mc.hit.hitTest(rocket_mc._x, rocket_mc.getBounds(_root).yMin, true)) { flag = true; }
  if(flag == true and rocket_obj.live == true) {
     blowUp();
   } // end if
 


is there any way to do this in AS3? It seems that they took out the hitTest funtion

Answers: Collision Detection with AS3 ( kirupaForum ActionScript 3.0 )
Collision Detection with AS3

Hey Gregmax, try hitTestObject().

If you're not sure what the AS3 equivalent is, you can always go into the Help and look through the properties and methods for that class.

motionsmith

Collision Detection with AS3

Does it check irregular shapes like lets say, a big blob? I did read about it and mentioned it checks the boundaries of that object/movieclip. Is there a certain way using it? If so how?

Thanks

gregmax

Collision Detection with AS3

if you want to test irregular shapes against points, you'll want to look into hitTestPoint. so for your question, here's an example of doing just that.

ActionScript Code:
//hitTestPoint(x, y, shapeflag)
if (mc.hitTestPoint(mouseX, mouseY, true)) {
        trace("hit!")
    }



another thing is that getBounds is used differently in as3. since the getBounds method returns an instance Rectangle, you would first create that rectangle with a variable so you can reference it later. once you have done that, you have access to it's properties:left, right, top, and bottom, which are the equivalents of xMin, xMax,...etc.

ActionScript Code:
var boundaries:Rectangle = mc.getBounds(this)

Exodar

Collision Detection with AS3

If you want to do pixel-level collision detection, check out BitmapData.hitTest().

If you're drawing in the Flash IDE, then you'll have to call the BitmapData.draw() method first in order to turn it into a bitmap. Grant Skinner does it here in Flash 8, so you can just take the concept, and apply it to your game.

motionsmith

Collision Detection with AS3

Actually, here's an AS3 version of Grant Skinner's CollisionDetection class. You can use this to test two irregular shapes.

motionsmith

Collision Detection with AS3

ok, I found this script, but isn't working for me

here is the link: http://www.adventuresinactionscript....sion-detection

and my problem is that I have a movieclip on the main timeline and a nested movie clip to do this collision detection stuff... any idea on how to work around this :/

thanks

gregmax

Previous Question:  wicked filter effect explanation  kirupaForum  ActionScript 3.0Next Question:  Unsigned int fun  kirupaForum  ActionScript 3.0

- Source: Collision Detection with AS3 kirupaForum ActionScript 3.0
- Previous Question: wicked filter effect explanation kirupaForum ActionScript 3.0
- Next Question: Unsigned int fun kirupaForum ActionScript 3.0