我如何在单体组中绘制线条?
几天前,我刚刚开始学习单体组,我想知道如何从start vector2和具有特定行厚度的End vector2绘制一条线?
我是否应该使用一个像素图像将其绘制到屏幕上,然后使用Bresenham的线算法来查找位置,还是使用函数内置的单game来进行更优化且更复杂的方法来执行此操作?
I just started learning monogame a couple of days ago and I was wondering how I can draw a line from a Start Vector2 and an End Vector2 with a specific line thickness?
Should I use a one pixel image to draw it onto the screen and then use a Bresenham's line algorithm to find there positions, or is there a more optimized and less complicated method to do this using monogames built in functions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种方法是创建一个
texture2d
,其宽度是两个vector2
s与所需宽度的高度之间的距离。然后,当您绘制纹理时,将旋转旋转应用于纹理。这是一个示例(作为
SpriteBatch
扩展方法):使用示例:
<
a href =“ https://i.sstatic.net/3ccccc9.png” rel =“ nofollow noreferrer“>
这不是一个完美的解决方案。如果您想以不同的角度绘制连接的线路,而没有任何可见的接缝,则需要对其进行修改。也不确定性能。
One way is to create a
Texture2D
with a width that is the distance between the twoVector2
s and a height that is the desired width. Then you apply a rotation to the texture when you draw it.Here is an example (as a
SpriteBatch
extension method):Example of use:
How it looks:
It's not a perfect solution. You'll want to modify it if you want to draw connected lines with different angles without any visible seams. Also not sure about the performance.
我使用我发现的库。它绘制了许多2D原语,例如行,框等。真的很容易使用。称为“ c3.mnogame.primitives2d”,可以在此处找到:
https://github.com/z2oh/c3.monogame.primitives.primitives2d
这是一个screenshot我使用许多方法写的演示:
这只是一个约500行的一个文件。如果您不喜欢git或使用库,则只需复制&amp;将其粘贴到您的项目中。
I use a library I found. It draws a number of 2D primitives, like lines, boxes, etc. Really easy to use. Called "C3.MonoGame.Primitives2D", it can be found here:
https://github.com/z2oh/C3.MonoGame.Primitives2D
Here's a screenshot of a demo I wrote using many of its methods:
It's just one file of around 500 lines. If you don't like Git or using libraries, you can just copy & paste it into your project.