3 つの長方形のブロックがあります: グラウンド ブロック、ブルー ブロック、ヒーロー ブロックです。画面の下部に地面が配置され、青いブロックが地面ブロックの上に置かれ、ヒーロー ブロックが青いブロックに落ちています。ヒーローが地面に触れたことを検出するリスナーがあります。2 つの状況があります: 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;
}