Ian*_*son 6 c# xna farseer windows-phone-7 xna-4.0
我正在开发一个wp7游戏,其中玩家在程序中绘制线条并且球从它们反弹.我正在使用XNA和farseer物理.用户绘制直线,然后让程序将其转换为物理对象或至少是vector2s列表的最佳方法是什么?我已经尝试创建一个TouchLocations列表,但是如果用户没有画得很慢,就像我附上的图片一样,它会变得不稳定.有什么建议?谢谢 http://img829.imageshack.us/img829/3985/capturehbn.png
这是一些代码:我正在使用gamestatemanagement示例,这是在HandleInput方法中
foreach (TouchLocation t in input.TouchState) {
pathManager.Update(gameTime, t.Position);
}
Run Code Online (Sandbox Code Playgroud)
pathManager类管理路径类的集合,这些路径类是可绘制的物理对象.这是pathManager.Update
public void Update(GameTime gameTime, Vector2 touchPosition) {
paths.Add(new Path(world,texture, new Vector2(5,5) ,0.1f));
paths[paths.Count-1].Position = touchPosition;
}
Run Code Online (Sandbox Code Playgroud)
这就是我现在正在做的事情,我愿意把它扔掉.您认为每个触摸位置都有一个5x5的矩形会破坏性能,但使用farseer我没有看到任何掉落,即使是大多数全屏.但是,如果快速绘制线,则此系统根本不会创建平滑线.
我怀疑这有什么帮助,但这里是Path构造函数.
public Path(World world, Texture2D texture, Vector2 size, float mass) {
this.Size = size;
this.texture = texture;
body = BodyFactory.CreateRectangle(world, size.X * pixelToUnit, size.Y * pixelToUnit, 1);
body.BodyType = BodyType.Static;
body.Restitution = 1f;
body.Friction = 0;
body.Friction = 10;
}
Run Code Online (Sandbox Code Playgroud)
绘制图元的最佳方法是使用 basiceffect 着色器。这将通过硬件加速。如果您愿意,还可以为其添加纹理。
我不确定它在 WP7 上是否相同,但这至少适用于 Windows7。