开发者

How can I get the object Type from a HitTest?

For practice, I'm coding a really simple 2D platforming game in Flash using AS3. I'd like to define two different types of terrain surfaces that the player can walk on based on classic platforming elements. Type1: the player can walk on, and if the player jumps, they will hit their head on it and bounce back to the ground. Type2: the player can also walk on, but if the player jumps and hits their head, they will simply pass through the surface and not bounce back to the ground.

I am using hitTestPoint to resolve collisions for this. My question is: What would be the best method to test for what TYPE of ground I am colliding with? Each ground type has it's own Class associated with it in my Flash IDE and all the different terrain surface types are in the same movie clip on the stage.

Currently I'm testing to see if it hit one type of ground surface, then i'm testing if it hit the other, and then based on those results, I process what I want to happen. This seems to work okay right now, but I'm imagining that I may want to create more than 2 types of ground to coll开发者_高级运维ide with. For example, moving platforms. It seems like the code will start to get complex

Eg.

if(_groundType1.hitTestPoint(_player.x, _player.y, true))
{
   if(_groundType2.hitTestPoint(_player.x, _player.y, true))
   {
       //don't hit the players head
   }

   //hit the players head
} 


Try using instanceof - http://www.adobe.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary389.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜