• Advertisement
Sign in to follow this  

Drawing Ball Path using XNA

This topic is 2079 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello, I am currently making a golf ball game using C# and XNA.
So far I have been able to make the ball fly, bounce, and roll, while displaying the position and velocity.
Now I want to be able to see the ball path (similar to images below), in order to check the whole ball movement.

![golf ball path](http://www.golf-simu.../images/ms4.jpg)

My code updates the ball position at a fixed time interval. I am thinking of:
1) using these position,
2) insert them to an array of VertexPositionColor[],
3) and draw them using GraphicsDevice.DrawUserPrimitives<VertexPositionColor>() method

but I have no luck so far, the VertexPositionColor is static array, while the amount of position data is always increasing.

I am thinking of using List<VertexPositionColor>, but the GraphicsDevice.DrawUserPrimitives<VertexPositionColor>() method refuse to take that as an input

protected override void Draw(GameTime gameTime) {
trail_vertice = new VertexPositionColor;
trail_vertice.Position = Position;
trail_vertice.Color = Color.Black;
trail_amount += 1;

graphics.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineStrip, trailList, 0, trail_amount);

I do not need an advanced effect like using particle engine. Just a single line is enough. Any suggestion?

Thanks in advance

Share this post

Link to post
Share on other sites
[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

[background=rgb(250, 251, 252)]List<VertexPositionColor> has a ToArray() function that will convert it to type VertexPositionColor[][/background]


[font="helvetica, arial, verdana, tahoma, sans-serif"][size="2"][color="#282828"]For the sake of speed though, i'd suggest keeping it as the array to begin with and just set it so its initailised with a predetermined maximum size, eg new VertexPositionColor[256]; [/font][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=1]If you go to add more verticies, and the array is full, then you can start treating it like a ring/circle buffer and forget the oldest points.[/font]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement