0

こんにちは、別のクラスで Game を参照しようとしている XNA ゲームに問題がありますが、何かを試すたびに、それをオーバーライドする適切な方法がないと表示されるので、Mouse.SetPosition(window.ClientBounds.Width / 2, window.ClientBounds) を使用できます。 .高さ / 2); game1.cs 以外の別のクラスでは、game1 の私のコードは

namespace _3d
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
    GraphicsDeviceManager graphics;
    SpriteBatch spriteBatch;


    MouseState mState;

    List<gameObject> gameobjectlist = new List<gameObject>();

    terrain Terrain;
    Camera mycam;

    Turret_Base turretBase;
    Turret_Barrel turretBarrel;
    //physicsObject Missile;


    public Game1()
    {
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";
    }

    /// <summary>

    /// This is where it can query for any required services and load any non-graphic
    /// related content.  Calling base.Initialize will enumerate through any components
    /// and initialize them as well.
    /// </summary>
    protected override void Initialize()
    {
        // TODO: Add your initialization logic here



        mycam = new Camera(MathHelper.ToRadians(45.0f),
            (float)graphics.GraphicsDevice.Viewport.Width / 
        (float)graphics.GraphicsDevice.Viewport.Height,
        1.0f, 10000.0f, Vector3.Zero, Vector3.Up);
        mycam.Position = new Vector3(0.0f, 53.0f, 155.0f);

        //MouseState mouseState = Mouse.GetState();
        //Vector3 mousePosition = new Vector3(mouseState.Y, mouseState.X, 0.0f);





        base.Initialize();
    }

    /// <summary>
    /// LoadContent will be called once per game and is the place to load
    /// all of your content.
    /// </summary>
    protected override void LoadContent()
    {
        // Create a new SpriteBatch, which can be used to draw textures.
        spriteBatch = new SpriteBatch(GraphicsDevice);
        Terrain = new terrain("models/terrain/desert", Content);
        turretBase = new Turret_Base("models/turret/Turret_Base", Content);
        turretBarrel = new Turret_Barrel("models/turret/Turret_Barrel", Content);
        //Missile = new physicsObject("models/turret/ammo", Content);

        gameobjectlist.Add(Terrain);
        gameobjectlist.Add(turretBase);
        gameobjectlist.Add(turretBarrel);
        gameobjectlist.Add(mycam);


        // TODO: use this.Content to load your game content here
    }

    /// <summary>
    /// UnloadContent will be called once per game and is the place to unload
    /// all content.
    /// </summary>
    protected override void UnloadContent()
    {
        // TODO: Unload any non ContentManager content here
    }

    /// <summary>
    /// Allows the game to run logic such as updating the world,
    /// checking for collisions, gathering input, and playing audio.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void update(GameTime gameTime)
    {


        // Allows the game to exit
        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            this.Exit();


        foreach (gameObject go in gameobjectlist)
        {
        }




        mycam.update(gameTime);

        Terrain.update(gameTime);
        turretBase.update(gameTime);
        turretBarrel.update(gameTime);

        if (exitGame() == false)
        {
            base.Update(gameTime);
        }

        // TODO: Add your update logic here


    }

    /// <summary>
    /// This is called when the game should draw itself.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.CornflowerBlue);

        foreach (gameObject go in gameobjectlist)
        {
        }


        // TODO: Add your drawing code here


        Terrain.draw(mycam);
        turretBase.draw(mycam);
        turretBarrel.draw(mycam);

        base.Draw(gameTime);
    }

    bool exitGame()
    {
        if (Keyboard.GetState().IsKeyDown(Keys.Escape))
        {
            Exit();
            return true;
        }
        return false;
    }
    } 
   }

そして、私がそれを入れようとしているクラスは>>

{
class Turret_Base : gameObject 



 {
    Turret_Barrel Parent;

    public Turret_Base(string fileName, ContentManager content, Turret_Barrel parent =      
    null)
        : base(fileName, content)
    {

        GameWindow window;
        Parent = parent;
        Pitch = 25;
        Yaw = 0;
        Roll = 0;
        Position = new Vector3(0, 50, 120);
        Scale = 0.1f; //Base Transform

    }

    public override void update(GameTime gametime)
    {
        float dt = (float)gametime.ElapsedGameTime.TotalSeconds;

        // mouse movement
        //MouseState mState = Mouse.GetState();

        //Vector3 newPos = new Vector3(mState.X, Position.Y, mState.Y);

        //Position = newPos;

        KeyboardState keyboardstate = Keyboard.GetState();
        if (keyboardstate.IsKeyDown(Keys.W))
            Position -= Vector3.UnitZ * 25.0f * dt;
        if (keyboardstate.IsKeyDown(Keys.A))
            Position -= Vector3.UnitX * 25.0f *dt;
        if (keyboardstate.IsKeyDown(Keys.S))
            Position += Vector3.UnitZ * 25.0f * dt;
        if (keyboardstate.IsKeyDown(Keys.D))
            Position += Vector3.UnitX * 25.0f * dt;



        base.update(gametime);


    }
}

}

明らかな間違いならごめんなさい

ありがとう

4

0 に答える 0