XNA 拉伸精灵
我想根据运动/速度方向拉伸精灵。为了简单起见,精灵是白色的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是不久前的事了,所以对于最初提出请求的人来说可能没有多大用处。但你有三个选择。一种是使用
Draw(Texture2D, Rectangle, ... )
而不是Draw(Texture2D, Vector2 ...)
。Vector2
仅设置x
和y
坐标,因此如果您使用该方法调整大小,您将调整整个精灵的大小。矩形包含X
、Y
和单独的高度和宽度值,因此使用矩形可以沿一个轴调整大小。您仍然会遇到末端问题,但这可以通过将末端视为单独的精灵来解决。我将此方法用于可变大小的边框。第二个方法适用于您所描述的简单精灵的情况,是在运行时创建纹理。创建所需大小的新.SetData(Color[]).这有相当多的计算开销,但我用它在运行时突出显示可变大小的边界框,所以它工作正常。
Texture2D
,然后创建一个足够大以覆盖每个像素的颜色数组,并使用当然,基元选项看起来也不错。 :)
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 thanDraw(Texture2D, Vector2 ...)
. TheVector2
just sets thex
andy
coordinates, so if you resize using that method you will resize the sprite as a whole. The Rectangle containsX
,Y
& separateHeight
andWidth
values, so using theRectangle
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. :)
我认为你必须创建多个精灵来显示该线。您需要线条内部部分的过渡精灵和端点的精灵。
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.
请清楚地说出你的问题。您可以上传任何截图吗?但据我了解,您应该使用距离公式在 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.