如何在XNA Visual Studio中使用拇指杆对360度移动进行编码
好的,我准备做一个游戏,它围绕着玩家控制的一个圆圈。这个游戏是自上而下的。枪指向北方或“向上”。我已经创建了一个精灵表,其中枪指向每个直角之间的4个方向。因此,在枪的指向和它的指向之间,还有4个其他位置。这一点在所有方面都是正确的 我想做的是对游戏进行编码,这样,如果你将右手的拇指杆旋转一圈,它将使枪在360度左右旋转。但我不知道如何做到这一点,因为到目前为止我只研究过基本的方向。即使我让拇指棒轴运行,我也不确定我将如何引用每个点作为拇指棒的位置 非常感谢您的帮助如何在XNA Visual Studio中使用拇指杆对360度移动进行编码,xna,rotation,controls,Xna,Rotation,Controls,好的,我准备做一个游戏,它围绕着玩家控制的一个圆圈。这个游戏是自上而下的。枪指向北方或“向上”。我已经创建了一个精灵表,其中枪指向每个直角之间的4个方向。因此,在枪的指向和它的指向之间,还有4个其他位置。这一点在所有方面都是正确的 我想做的是对游戏进行编码,这样,如果你将右手的拇指杆旋转一圈,它将使枪在360度左右旋转。但我不知道如何做到这一点,因为到目前为止我只研究过基本的方向。即使我让拇指棒轴运行,我也不确定我将如何引用每个点作为拇指棒的位置 非常感谢您的帮助 //从棒中获取旋转:(从内存中
//从棒中获取旋转:(从内存中获取,som可能是反向顺序等)
//Gets us the rotation from the stick: (taking this from memory, som might be reverse order etc)
float radians = Math.Atan2(GamePadState.ThumbSticks.Left.Y, GamePadState.ThumbSticks.Left.X);
//Top half: 0 = stick to the right to Pi = stick to the left.
//Bottom half: 0 = stick to the right to -Pi = stick to the left.
//I'll just do this for 4 directions, as I have limited time, and the concept should be obvious:
if ((radians > Math.Pi * -0.25f) && (radians < Math.Pi * 0.25f))
//Direction is Right
else if ((radians >= Math.Pi * 0.25f) && (radians < Math.Pi * 0.75f))
//Direction is Up
else if ((radians >= Math.Pi * 0.75f) || (radians <= Math.Pi * -0.75f))
//Direction is Left
else if ((radians <= Math.Pi * -0.25f) && (radians > Math.Pi * -0.75f))
//Direction is Down
float radians=Math.Atan2(GamePadState.ThumbSticks.Left.Y,GamePadState.ThumbSticks.Left.X);
//上半部分:0=向右移动到Pi=向左移动。
//下半部分:0=向右移动到-Pi=向左移动。
//我将在4个方向上这样做,因为我的时间有限,概念应该是显而易见的:
如果((弧度>数学Pi*-0.25f)和&(弧度<数学Pi*0.25f))
//方向是正确的
else if((弧度>=Math.Pi*0.25f)和&(弧度=Math.Pi*0.75f)| |(弧度=0.5f)(东北、东北、东南)
{
如果(斗杆Y>=0.5f)
//方向是东北
否则,如果(粘住
Vector2 stick = GamePadState.ThumbSticks.Left;
stick.Normalize();
if (stick.X >= 0.5f) (NE, E, SE)
{
if (stick.Y >= 0.5f)
//Direction is NE
else if (stick.Y <= -0.5f)
//Direction is SE
else
//Direction is E
}
else if (stick.X <= -0.5f) (NW, W, SW)
{
if (stick.Y >= 0.5f)
//Direction is NW
else if (stick.Y <= -0.5f)
//Direction is SW
else
//Direction is W
}
else if (stick.Y >= 0.5f)
//Direction is N
else if (stick.Y <= -0.5f)
//Direction is S
else
//Direction is nothing. should not happen