我有三个矩形块:地面块,蓝色块,英雄块。地面放置在屏幕底部,蓝色块放在地面块上,英雄块下降到蓝色块。我有侦听器,可以检测英雄何时触地。有两种情况: 1)当英雄从低处跌落到蓝块时,它的ok监听器通知英雄只接触蓝块。2) 当英雄从稍高一点的高度跌落到蓝色方块时,监听器通知英雄触地!!!如何解决这个问题?
这是英雄 OnCollision 监听器:
bool heroBody_OnCollision(Fixture fixtureA, Fixture fixtureB, Contact contact)
{
Texture2D textureB = (Texture2D)fixtureB.UserData;
string textureBName = ((string)textureB.Tag).ToLower();
if (textureBName == "ground")
{
OnHeroTouchedGround();
return true;
}
else if (textureBName.Contains("blue"))
{
OnHeroTouchedBlueBlock();
return true;
}
return true;
}
public HeroState GetHeroState()
{
ContactEdge contactEdge = null;
if (heroBody != null) contactEdge = heroBody.ContactList;
while (contactEdge != null)
{
if (heroBody.LinearVelocity == Vector2.Zero)
{
Texture2D textureA = (Texture2D)contactEdge.Contact.FixtureA.UserData;
string textureAName = ((string)textureA.Tag).ToLower();
Texture2D textureB = (Texture2D)contactEdge.Contact.FixtureB.UserData;
string textureBName = ((string)textureB.Tag).ToLower();
if (textureAName == "ground" || textureBName == "ground")
return HeroState.OnGroud;
else if (textureAName.Contains("blue") || textureBName.Contains("blue"))
return HeroState.OnHome;
}
contactEdge = contactEdge.Next;
}
return HeroState.Playing;
}