执行此操作所需的公式究竟是什么?
所以如果我有两个单独的 Sprite ,分别命名为 player(宇宙飞船)和 exhaust(宇宙飞船底部的排气动画)
需要什么数学运算,以便当玩家旋转时,排气装置移动并将其自身定位在船的底部,如果玩家向右旋转 90 度,此时可能位于左侧。
我知道如何旋转/旋转 Sprite 以面向正确的方向。我需要知道的是如何移动排气装置,以便在船转弯时将其正确定位在船底。
并且请不要链接任何“围绕一个点移动 Sprite ”线程等,因为这不是我要找的。p>
最佳答案
假设这艘船类似于游戏“Asteroids”中的那艘船,船尾的位置(相对于船的中心)将由一个圆来描述,该圆的半径是中心与船的中心之间的距离船和船尾。
鉴于此,您可以像这样计算船尾的位置:
#include <math.h>
[...]
double radius = ship_height/2.0;
double ship_heading = /* current angle of rotation of the ship, in radians, e.g. 0 if the ship is facing right, pi if it is facing left, etc */
double tail_heading = ship_heading + 3.14159; /* ship's tail faces the opposite direction from the nose! */
double x_offset = cos(tail_heading)*radius;
double y_offset = sin(tail_heading)*radius;
double exhaust_center_x = ship_center_x + x_offset;
double exhaust_center_y = ship_center_y + y_offset;
(如果你想让排气图形出现在离船尾稍远的地方,只需稍微增加半径值即可)
关于C++ 2D 如何将 "stick"宇宙飞船上的排气 Sprite 并允许它相应地旋转?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27785772/