绘制矩形与纹理不在同一个位置

时间:2013-05-10 11:18:31

标签: c# xna

这导致与其他对象的碰撞而无法正常工作,

我觉得它可能与我们如何为玩家旋转精灵有关,下面是我们用于旋转的代码

#region draw player

        if (player.facing == 4)

            spriteBatch.Draw(player.txr, player.drawRect, null, Color.White, 1.5708f, new Vector2(player.drawRect.Width / 2, player.drawRect.Height / 2), SpriteEffects.None, 0);

        else if (player.facing == 3)

            spriteBatch.Draw(player.txr, player.drawRect, null, Color.White, 4.712389f, new Vector2(player.drawRect.Width / 2, player.drawRect.Height / 2), SpriteEffects.None, 0);

        else if (player.facing == 1)

            spriteBatch.Draw(player.txr, player.drawRect, null, Color.White, 0, new Vector2(player.drawRect.Width / 2, player.drawRect.Height / 2), SpriteEffects.None, 0);

        else if (player.facing == 2)

            spriteBatch.Draw(player.txr, player.drawRect, null, Color.White, 3.14593f, new Vector2(player.drawRect.Width / 2, player.drawRect.Height / 2), SpriteEffects.None, 0);

        else if (player.facing == 5)

            spriteBatch.Draw(player.txr, player.drawRect, null, Color.White, 0.785398163f, new Vector2(player.drawRect.Width / 2, player.drawRect.Height / 2), SpriteEffects.None, 0);

        else if (player.facing == 6)

            spriteBatch.Draw(player.txr, player.drawRect, null, Color.White, 2.094395102f, new Vector2(player.drawRect.Width / 2, player.drawRect.Height / 2), SpriteEffects.None, 0);
        else if (player.facing == 7)

            spriteBatch.Draw(player.txr, player.drawRect, null, Color.White, 3.839724354f, new Vector2(player.drawRect.Width / 2, player.drawRect.Height / 2), SpriteEffects.None, 0);
        else if (player.facing == 8)

            spriteBatch.Draw(player.txr, player.drawRect, null, Color.White, 5.497787144f, new Vector2(player.drawRect.Width / 2, player.drawRect.Height / 2), SpriteEffects.None, 0);
        #region DEBUG
        //spriteBatch.Draw(Door.txr, player.drawRect, Color.White);
        //spriteBatch.Draw(Door.txr, player1.drawRect, Color.White);
        //spriteBatch.Draw(Door.txr, player2.drawRect, Color.White);
        //spriteBatch.Draw(Door.txr, player3.drawRect, Color.White);
        #endregion

1 个答案:

答案 0 :(得分:0)

绘制精灵批处理只会在旋转中渲染精灵。您为播放器设置的碰撞盒以及如何处理它是一个单独的问题。您必须使用与绘制时相同的旋转来转换播放器碰撞框。