我刚刚开始使用Farseer Physics,并且创建了一个快速/粗略的基础对象,可以用来轻松创建对象。
所以我设置了一个快速模拟,它看起来像这样:
在 DebugView 中,它看起来像这样:
经过仔细检查,在启用这两种模式的情况下,我可以看到橙色框缺少一行和一列像素:
有谁知道为什么会这样?
class BasePhys
{
public float unitToPixel;
public float pixelToUnit;
public Vector2 size;
public Body body;
public Texture2D texture;
public BasePhys(World world, int x, int y)
{
this.unitToPixel = 100.0f;
this.pixelToUnit = 1 / unitToPixel;
TextureManager.GetTextureByName("base", ref this.texture);
this.size = new Vector2(this.texture.Width, this.texture.Height);
this.body = BodyFactory.CreateRectangle(world, this.size.X * this.pixelToUnit, this.size.Y * this.pixelToUnit, 1);
this.body.BodyType = BodyType.Dynamic;
this.body.Position = new Vector2(x * this.pixelToUnit, y * this.pixelToUnit);
}
public void Draw(SpriteBatch spriteBatch)
{
Vector2 scale = new Vector2(this.size.X / (float)this.texture.Width, this.size.Y / (float)this.texture.Height);
Vector2 position = this.body.Position * unitToPixel;
spriteBatch.Draw(this.texture, position, null, Color.White, this.body.Rotation, new Vector2(this.texture.Width / 2.0f, this.texture.Height / 2.0f), scale, SpriteEffects.None, 0);
}
}
有谁知道为什么会这样?在所有的 Farseer 演示中都没有这样做。我检查了纹理,它没有不可见pixels
的橙色pixels
填充整个文件。