随着 x/y 坐标的变化进行适当的旋转
我正在尝试制作一个小弓箭手游戏,我遇到的问题特别与 2 个像素有关,我将它们称为 _arm 和 _arrow。真正的弓箭手在拉箭的时候,不会立即将箭拉到力气允许的范围内,而是需要一点时间才能拉回来。 _arm 的角度等于从一点到用户在屏幕上触摸的位置的矢量。旋转是完美的,所以 _arm 很好。 _arrow 需要与 _arrow 在同一行,它们各有 1 像素宽,因此看起来 _arrow 正好位于 _arm 的顶部。
我尝试根据随时间变化的变量来递减 x/y 坐标,并将 _arrow 的位置设置为等于 _arm 的位置,并尝试使其看起来像是 _arrow 被拉回。但是,如果旋转,x/y 会混乱,因为它在 x 和 y 轴上不成比例,所以基本上 _arrow 会稍微高于手臂或稍微低于手臂,具体取决于矢量的角度(基于触摸) 。
我如何使用 _arm 的 x/y 位置和触摸向量使箭头看起来好像被稍微拉回,但又将箭头保持在 _arm 精灵的顶部,以便它的位置相似到手臂,但稍微偏离,但始终位于 _arm 像素的顶部。如果您需要更多信息,请发表评论。
I'm trying to make a little archer game, and the problem I'm having has to do with 2 pixels in particular, I'll call them _arm and _arrow. When a real archer is pulling back an arrow, he doesn't immediately pull the arrow back as far as his strength allows him, the arrow takes a little bit of time to be pulled back.
The _arm's angle is equal to the vector from a point to where the user touched on the screen. The rotation is perfect, so the _arm is good. The _arrow needs to be on the same line as _arrow, they are 1 pixel wide each so it looks as though the _arrow is exactly on top of the _arm.
I tried to decrement from the x/y coordinates based on a variable that changes with time, and I set the _arrow's location equal to the _arm's location, and tried to make it look like the _arrow was being pulled back. however, if you rotated, the x/y would mess up because it is not proportional on the x and y axis, so basically _arrow will either be slightly above the arm or slightly below it depending on the angle of the vector, based on touch.
How could I used the x/y position of _arm and the vector of touch to make the arrow appear as though it was being pulled back by a small amount, yet keep the arrow on top of the _arm sprite so that it's position would be similar to the arm, but slightly off yet still on top of the _arm pixel at all times. If you need anymore info, just leave a comment.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定我是否完全理解,但无论如何我都会尝试回答:
要使箭头移动并旋转到与考虑将箭头添加为手臂的子项相同的位置。如果您愿意,您仍然可以将其渲染在后面,方法是使其 z 小于 1:
[arm addChild:arrow z:-1]
然后在拉弓时使箭头远离手臂,然后只需设置箭头相对于手臂的位置。
然而,我确实看到这个解决方案的问题是,在箭头离开弓之后,精灵的这种分组可能有点不寻常。在这里,您可能不希望箭头成为手臂的子项,因为坐标系不再相关。
尽管他们确信我“建议的内容可以解决[问题]”,但这里是
发帖者的解决方案
I'm not sure I've fully understood, but I'll have a go at answering anyway:
To make the arrow move and rotate to the same place as the consider adding the arrow as a child of the arm. You can still render it behind if you like by making its z is less than one:
[arm addChild:arrow z:-1]
To then make the arrow move away from the arm as the bow is drawn, you then just set the position of the arrow with respect to the arm.
The problem I do see with this solution however is that this grouping of the sprites may be a little unusual after the arrow leaves the bow. Here you probably don't want the arrow to be a child of the arm as the coordinate systems are no longer related.
Even though they're sure what I "suggested would have solved [the] problem" here is the
Poster's solution