2011-05-08 43 views
3

我不知道爲什麼,但我似乎無法找出爲什麼這不起作用... 我試圖做一些非常簡單的事情,就像剛剛脫離屏幕的東西。更加虛擬的物理......你好世界......?

它似乎與最新的下載和網站上的第一個示例代碼,我仍然是錯誤的。

我有這樣的:

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搞砸了嗎?

回答

3

Their example是錯的,你說得對! (我很驚訝他們有這樣明顯的錯誤。)

轉到類CircleShape並查看參數的順序。圓是由位置和半徑來定義的,而不僅僅是半徑。

然後搜索您的項目的CreateBody(),看看應該從哪裏調用該方法。

+2

Ahh'FarseerPhysics.Factories.BodyFactory.CreateBody()'也許 – 2011-05-08 20:53:44

+1

我也推薦下載XNA Testbed示例,因爲它們展示瞭如何使用某些方法:http://farseerphysics.codeplex.com/releases/view/64108。您也可以通過瀏覽源代碼中的「示例」部分獲取更多代碼示例:http://farseerphysics.codeplex.com/SourceControl/changeset/view/88395 – keyboardP 2011-05-08 20:55:47

+0

@keyboardp非常感謝!第二個鏈接給了我一些幫助我很多的資源 – 2011-05-08 21:02:28