使用浮点值在XNA中绘制线条

时间:2013-03-12 10:03:33

标签: c# winforms xna-4.0

如何使用浮点值在XNA(C#)中绘制线,而不是整数,因为整数除去了点之后的值

喜欢:20.12

1 个答案:

答案 0 :(得分:0)

您可以尝试使用SpriteBatch.Draw (Texture2D, Vector2, Nullable<Rectangle>, Color, Single, Vector2, Vector2, SpriteEffects, Single) method。 您需要先创建一个代表您的行的Texture2D

Vector2 pos = new Vector2(20.12F, 20.12F);
Vector2 scale = new Vector2(150.23F, 1);
Color myColor = Color.Blue;

Texture2D simpleTexture = new Texture2D(GraphicsDevice, 1, 1, false, SurfaceFormat.Color);

// Draws a "line" with size (1, 1), at position (20.12, 20.12), with blue color, rotated by 45° (Pi/4), with origin at (0, 0) (the line will begin at 'pos'), scaled by (150.23, 1) (gives the line a size of (150.23, 1) )
this.spriteBatch.Draw(simpleTexture, pos, null, myColor, MathHelper.PiOver4, Vector2.Zero, scale, SpriteEffects.None, 0)

我使用XNA已经很久了,所以我不能保证这会起作用 无论如何,我希望它有所帮助。