移动精灵以匹配 XNA 中圆的边框



我正在尝试在 xna 中构建一个游戏,我得到了一个圆圈,我希望玩家在它周围移动,如下图所示,除了我不满意的绘图部分外,它运行良好这是指向图像 http://s12.postimage.org/poiip0gtp/circle.png 的链接

我想将玩家对象居中到圆圈的边缘,这样玩家就不会看起来像站在空中

这就是我计算玩家位置的方式

rad = (degree * Math.PI / 180);
            rotationDegree = (float)((Math.PI * degree) / 180);
            currentPosition.X = (float)(Math.Cos(rad) * Earth.radius + (GraphicsDevice.Viewport.Width / 2));
            currentPosition.Y = (float)(Math.Sin(rad) * Earth.radius + (GraphicsDevice.Viewport.Height / 2));

这就是我画球员的方式

spriteBatch.Draw(texture,currentPosition, null, Color.White,rotationDegree, Vector2.Zero,1f,SpriteEffects.None, 1f);

谢谢。

对精灵批处理使用源重载。这是根据位置绘制精灵的地方。

Spritebatch.Draw(texture,Position, null,Color.White,0f,new Vector2(texture.Width / 2,texture.Height /2),1f,SpriteEffects.None, 0);

使用texture.Width / 2,texture.Height /2作为原点将使其居中。

看起来您要在此处做的是调整精灵的origin,这是您要传递到SpriteBatch.Draw()中的向量。 这用于确定精灵的"中心点"; {0, 0}代表精灵的左上角,而{spriteWidth, spriteHeight}代表右下角。 你的角色将相对于这个原点进行定位和旋转。

最新更新