Farseer ContactListener is not working
本文关键字:working not is ContactListener Farseer | 更新日期: 2023-09-27 18:14:22
我在XNA项目中使用Farseer,但是我在ContactListener上遇到了一些麻烦。我为我的ContactListener创建了一个类,但我总是得到这两个错误消息,我不知道如何解决问题。
类型或命名空间名称'ContactListener'找不到(您是否缺少using指令或程序集引用?)
类型或命名空间名称'ContactImpulse'找不到(您是否缺少using指令或程序集引用?)
我的ContactListener类有什么问题?
class MyContactListener: ContactListener
{
void BeginContact(Contact contact)
{ /* handle begin event */ }
void EndContact(Contact contact)
{ /* handle end event */ }
void PreSolve(Contact contact, ref Manifold oldManifold)
{
Fixture fixtureA = contact.FixtureA;
Fixture fixtureB = contact.FixtureB;
if (fixtureB.CollisionCategories == Category.Cat10)
{
contact.Enabled = false;
}
}
void PostSolve(Contact contact, ref ContactImpulse impulse)
{ /* handle post-solve event */ }
}
试试这个:
- 打开VS
- 进入
Solution Explorer
窗口 - 搜索名为
References
的文件夹并右键单击 - 选择
Add Reference...
- 查找Farseer组件并添加
并尝试在代码中添加这些:
using FarseerPhysics.Collision.Shapes;
using FarseerPhysics.Common;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Dynamics.Contacts;
using FarseerPhysics.Factories;
using FarseerPhysics.TestBed.Framework;
using Microsoft.Xna.Framework;