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?
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);
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_US/AS3LCR/Flash_10.0/ localToGlobal() AND globalToLocal()).
精彩评论