编程语言
首页 > 编程语言> > C#-Farseer物理学…你好,世界…?

C#-Farseer物理学…你好,世界…?

作者:互联网

我不知道为什么,但我似乎无法找出为什么这不起作用…
我正在尝试使某些事情变得非常简单,例如刚从屏幕上掉下来的东西.

好像在该站点上的最新下载和第一个示例代码中,我仍然错了.

我有这个:

using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Collections;
using Microsoft.Xna.Framework.Input;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Collision.Shapes;


namespace Cross {
    public class Game1 : Microsoft.Xna.Framework.Game {
        GraphicsDeviceManager graphics;

        public Game1() {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            graphics.IsFullScreen = false;
            graphics.PreferredBackBufferHeight = 600;
            graphics.PreferredBackBufferWidth = 1200;

            this.Window.Title = "Game";
        }


        protected override void Initialize() {
            World world = new World(Vector2.Zero);

            Body myBody = world.CreateBody();
            myBody.BodyType = BodyType.Dynamic;

            CircleShape circleShape = new CircleShape(0.5f);
            Fixture fixture = myBody.CreateFixture(circleShape);

            base.Initialize();
        }

        protected override void LoadContent() {

        }

        protected override void UnloadContent() {
        }


        protected override void Update(GameTime gameTime) {
            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime) {
            base.Draw(gameTime);
        }
    }
}

但是我得到两个错误:

没有CreateBody()方法(尽管有一个AddBreakableBody())

'FarseerPhysics.Dynamics.World' does not contain a definition for 'CreateBody' and no extension method 'CreateBody' accepting a first argument of type 'FarseerPhysics.Dynamics.World' could be found (are you missing a using directive or an assembly reference?)

CircleShape构造函数接受2个参数(这很简单,但在示例中仍然出错)

'FarseerPhysics.Collision.Shapes.CircleShape' does not contain a constructor that takes 1 arguments

我已经尝试了很多事情,但我很困惑为什么能得到这个.此代码对其他人有用吗?我的dll搞砸了吗?

解决方法:

Their example是错的,您是对的! (令我惊讶的是它们有如此明显的错误.)

转到CircleShape类,然后查看参数按哪个顺序排列.圆由位置和半径(而不仅仅是半径)定义.

然后在您的项目中搜索CreateBody(),以查看应从何处调用该方法.

标签:xna,method-missing,physics,c,farseer
来源: https://codeday.me/bug/20191208/2091441.html