Thursday, April 28, 2011

Actionscript 3: Is there a way to detect collisions between a class and a class within a class?

So I'm currently making a platformer game in flash. I want to detect a collision between my player class, and the enemy class. The enemy class is inside of a class called ground. I tried to detect it using hitTestPoint (ground.enemy.hitTestPoint(player.x, player.y, true)), but to no avail. How would I go about doing this?

From stackoverflow
  • Without seeing your code it's hard to say what's going on... what exactly didn't work with your hitTestPoint() approach? You might need to translate the player point coordinates to a value relative to ground (see: http://help.adobe.com/en%5FUS/AS3LCR/Flash%5F10.0/ localToGlobal() AND globalToLocal()).

    Miles : Well, as far as I know, flash didn't like that I was accessing hitTestPoint by ground.enemy.hitTestPoint? If this wasn't clear, I dragged the enemy movieclip onto ground's timeline, so I'm trying to detect a collision with that.
    heavilyinvolved : Posting some of your code or the error messages you are getting would be helpful in working towards a resolution.
  • Maybe it could be one of the following issues:

    • Have in mind that the hitTestPoint method work with the root coordinate system. If your player and ground objects are not both placed in the root, then some coordinate transformations will be needed.
    • The player.x and player.y values are located through the origin point within the player clip. If by chance the origin point lies outside the player graphic, then the hit test will fail since the coordinate you are checking will probably not be where you would expect.
    • If everything else fails, try to check that everything is working right by checking the hit test with the mouse: ground.enemy.hitTestPoint(stage.mouseX, stage.mouseY, true);

0 comments:

Post a Comment