1

私は、この質問が以前に回答されたことを理解しており、私を信頼して調査を行いました。これは学校向けのプロジェクトですが、ゲームプログラマーになることを考えると、自分の学習のためにこれをやりたいと思っています。

これは面倒になるかもしれませんが、最善を尽くしているので、これは基本的なシューティング ゲームとして始まりました。

entity.cs- は、プレイヤーが game.cs で player.draw (spritebatch) を呼び出すための spritebatch を既に開始しています。

player.cs - 弾丸の射撃と位置が含まれています

bullet.cs

敵.cs

だから私の問題は、マウスを見るようにスプライトを更新するためのコードがあることです。

player.Draw(
            playerTexture,
            position,
            null,
            Color.White,
            rotation,
            spriteOrigin,
            1.0f,SpriteEffects.None,0f);

game.cs の描画関数では、これを行うと、別のスプライト (プレイヤー スプライトと同じスプライト) が表示されますが、別のスプライトはマウスを表示しますが、もう 1 つのスプライトにはマウスを表示させたいと考えています。

しかし、私の教授。entity.cs で既に開始されているスプライト バッチが存在するようにコードを記述しました。

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);

    }

game.cs の描画関数 player.draw では、プレイヤーを描画するために呼び出されますが、そのスプライトのマウス効果を見るにはどうすればよいでしょうか?

public CPlayer(CGame game, Texture2D playerTexture)
        : base(game, playerTexture)
    {
        texture = playerTexture;
        brotation = rotation;



        position.X = 400f;
        position.Y = 400f;
    }

また、プレーヤーはエンティティから継承されます。

要求に応じてマウスを更新するためのコード

 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);
4

0 に答える 0