C# 在XNA游戏中遇到精灵问题看鼠标

C# 在XNA游戏中遇到精灵问题看鼠标,c#,mouse,xna-4.0,C#,Mouse,Xna 4.0,我知道这个问题以前已经得到了回答,我也做过研究,相信我。 我现在要说的是,这是一个学校的项目,但考虑到我将进入游戏程序员行业,我想为自己的学习做这个 这可能会弄得一团糟,但我会尽力的 因此,这是一个基本的拍摄开始,我们有一个 game.cs-包含所有纹理向量(不包括),以及 entity.cs-已开始spritebatch,玩家可以在中调用player.draw(spritebatch) game.cs player.cs-包含子弹的射击和位置 bullet.cs 敌方 所以我的问题是,我有更新

我知道这个问题以前已经得到了回答,我也做过研究,相信我。 我现在要说的是,这是一个学校的项目,但考虑到我将进入游戏程序员行业,我想为自己的学习做这个

这可能会弄得一团糟,但我会尽力的 因此,这是一个基本的拍摄开始,我们有一个 game.cs-包含所有纹理向量(不包括),以及

entity.cs-已开始spritebatch,玩家可以在中调用player.draw(spritebatch) game.cs

player.cs-包含子弹的射击和位置

bullet.cs

敌方

所以我的问题是,我有更新精灵的代码来查看鼠标,然后我会使用它

player.Draw(
            playerTexture,
            position,
            null,
            Color.White,
            rotation,
            spriteOrigin,
            1.0f,SpriteEffects.None,0f);
在game.cs draw函数中,但当我这样做时,我会得到另一个精灵(与我的玩家精灵相同的精灵),它确实看着我的鼠标,但我希望我的另一个精灵看着鼠标

但是我的朋友。编写代码以便entity.cs中已经有一个spritebatch

public CEntity(CGame myGame, Texture2D myTexture)
    {
        game = myGame;
        texture = myTexture;
    }

    /// <summary>
    /// Draws the player.
    /// </summary>
    /// <param name="begunSpriteBatch">Give this function a already begun SpriteBatch.</param>
    public void Draw(SpriteBatch begunSpriteBatch)
    {
        begunSpriteBatch.Draw(texture, position, Color.White);

    }
而且玩家是从实体继承的

用于根据请求更新鼠标的代码

 IsMouseVisible = true;

        MouseState mouse = Mouse.GetState();
        distance.X = mouse.X - position.X;
        distance.Y = mouse.Y - position.Y;
        //Math.Atan2((double)mouseState.Y - position.Y, (double)mouseState.X - position.X); was using this //before found a different way

        rotation = (float)Math.Atan2(distance.Y, distance.X);

        spriteRectangle = new Rectangle((int)position.X, (int)position.Y,//rotation stuff
            playerTexture.Width, playerTexture.Height);
        spriteOrigin = new Vector2(spriteRectangle.Width / 2, spriteRectangle.Height / 2);

你能给我们看一下“更新精灵看鼠标的代码”吗?有人吗?如果我需要补充更多,请告诉我现在我不确定我是否理解这个问题。现在我猜你所要做的就是把设置旋转的代码复制到另一个地方(或者更好,把它分离成一个可重用的函数),虽然我在origin方面遇到了一些麻烦,但我还是很感谢你的帮助。哦,ps独立游戏开发者太棒了,我希望有一天能成为你的棍棒忍者
 IsMouseVisible = true;

        MouseState mouse = Mouse.GetState();
        distance.X = mouse.X - position.X;
        distance.Y = mouse.Y - position.Y;
        //Math.Atan2((double)mouseState.Y - position.Y, (double)mouseState.X - position.X); was using this //before found a different way

        rotation = (float)Math.Atan2(distance.Y, distance.X);

        spriteRectangle = new Rectangle((int)position.X, (int)position.Y,//rotation stuff
            playerTexture.Width, playerTexture.Height);
        spriteOrigin = new Vector2(spriteRectangle.Width / 2, spriteRectangle.Height / 2);