XNA 拉伸精灵

发布于 2024-12-03 12:54:57 字数 234 浏览 1 评论 0原文

我想根据运动/速度方向拉伸精灵。为了简单起见,精灵是白色的 5x5 像素。包括黑色 1x1 边框

因此,例如,如果精灵从当前位置向“3 点钟”移动,它将像细线对角线一样拉伸/缩放,与基于随机移动的任何其他角度/弧度类似。

我尝试采用:vector2位置 - 原始位置,然后将其与:length()一起用于x和y比例值,但这会产生大比例块而不是线?

有什么想法吗?关于缩放和计算方向角

保罗。

I'd like to stretch a sprite based on the movemnt/velocity direction. for simplicity sake the sprite is white 5x5 pixels. including a black 1x1 border

So for example if the sprite moves from current location towards '3oclock' that it would stretch/scale like thin line diagonally, similar for any other angle/radian based on random movement.

I tried taking the: vector2 position - original position, and then using this with: length() for either x and y scale values but this produces large scale blocks and not a line?

Any ideas? on scaling and calculating the angle of direction

Paul.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

下雨或天晴 2024-12-10 12:54:57

这是不久前的事了,所以对于最初提出请求的人来说可能没有多大用处。但你有三个选择。一种是使用 Draw(Texture2D, Rectangle, ... ) 而不是 Draw(Texture2D, Vector2 ...)Vector2 仅设置 xy 坐标,因此如果您使用该方法调整大小,您将调整整个精灵的大小。矩形包含 XY 和单独的高度和宽度值,因此使用矩形可以沿一个轴调整大小。您仍然会遇到末端问题,但这可以通过将末端视为单独的精灵来解决。我将此方法用于可变大小的边框。

第二个方法适用于您所描述的简单精灵的情况,是在运行时创建纹理。创建所需大小的新 Texture2D,然后创建一个足够大以覆盖每个像素的颜色数组,并使用 .SetData(Color[]).这有相当多的计算开销,但我用它在运行时突出显示可变大小的边界框,所以它工作正常。

当然,基元选项看起来也不错。 :)

This was some time ago, so may not be much use to the original person who made the request. But you have three options. One is to use Draw(Texture2D, Rectangle, ... ) rather than Draw(Texture2D, Vector2 ...). The Vector2 just sets the x and y coordinates, so if you resize using that method you will resize the sprite as a whole. The Rectangle contains X, Y & separate Height and Width values, so using the Rectangle you can resize along one axis. You will still get a problem with the ends, but that can be fixed by treating the ends as separate sprites. I use this method for variable sized borders.

The second, which will work in the case of a simple sprite as you describe, is to create the texture at runtime. Create a new Texture2D of the desired size, then create an array of colors big enough to cover each pixel, and assign that array using <Texture2D>.SetData(Color[]). There is a fair bit of computational overhead with this, but I've used it to highlight a variable sized bounding box at runtime, so it works ok.

Of course, the primitives option looks good too. :)

岁月无声 2024-12-10 12:54:57

我认为你必须创建多个精灵来显示该线。您需要线条内部部分的过渡精灵和端点的精灵。

I think you'll have to create multiple sprites to display the line. You'll need transitional sprites for the inner sections of the line and sprites for the end points.

ヅ她的身影、若隐若现 2024-12-10 12:54:57

请清楚地说出你的问题。您可以上传任何截图吗?但据我了解,您应该使用距离公式在 X 方向上缩放精灵,然后使用 tan 反函数旋转它。

Please state your question clearly. Could you upload any screenshots? From what I understand, though, you should scale the sprite in X direction using the distance formula and then Rotate it using the tan inverse function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文