Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best method in XNA to have the player paint smoothly on the screen?

I'm developing a wp7 game where the player draws lines in the program and a ball bounces off of them. I'm using XNA and farseer physics. What is the best method for a user to draw a line, and then for the program to take it and turn it in to a physics object, or at least a list of vector2s? I've tried creating a list of TouchLocations, but it ends up spotty if the user does not draw very slow, like the picture I've attached. Any suggestions? Thanks http://img829.imageshack.us/img829/3985/capturehbn.png

Here's some code: I'm using the gamestatemanagement sample, and this is in the HandleInput method

foreach (TouchLocation t in input.TouchState) {
  pathManager.Update(gameTime, t.Position);
}

The pathManager class manages a collection of path classes, which are drawable physics objects. Here is 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;
}

This is just what I'm doing now and I'm willing to throw it out for anything. You'd think that having a 5x5 rectangle for each touch location would kill the performance, but using farseer I didn't see any drops, even with a mostly full screen. However, this system doesn't create a smooth line at all if the line is drawn fast.

I doubt this helps any, but here is the Path constructor.

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;
}
like image 518
Ian Wilson Avatar asked Dec 24 '12 16:12

Ian Wilson


1 Answers

How do I draw lines using XNA?

the best way to draw primitives is to use the basiceffect shader. this will be accelerated by the hardware. you can also add a texture to it if you'd like.

i'm not sure if its the same on WP7 but this works for Windows7 at least.

like image 131
ColacX Avatar answered Oct 04 '22 20:10

ColacX