Quantcast
Channel: Community | MonoGame - Latest topics
Viewing all articles
Browse latest Browse all 6821

Mouse does not work!

$
0
0

@Falk_Bruskeland wrote:

I've been working with Monogame the past three years, and it is great. But I've had some difficult with mouse position. It used to work, but if I use classes, it doesn't work. This is my test project:
Game1 class:

    GraphicsDeviceManager graphics;
    SpriteBatch spriteBatch;

    Playerclass Player;
    public Game1()
    {
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";
    }
    protected override void Initialize()
    {
        this.IsMouseVisible = true;
        base.Initialize();
    }
    protected override void LoadContent()
    {
        // Create a new SpriteBatch, which can be used to draw textures.
        spriteBatch = new SpriteBatch(GraphicsDevice);
        Player = new Playerclass();
        Player.LoadContent(Content);
    }
    protected override void UnloadContent()
    {
    }
    protected override void Update(GameTime gameTime)
    {
        Player.Update(gameTime, Mouse.GetState().Position.ToVector2());
        base.Update(gameTime);
    }
    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.CornflowerBlue);
        spriteBatch.Begin();
        //spriteBatch.Draw(Guy, Mouse.GetState().Position.ToVector2(), Color.White);
        Player.Draw(spriteBatch);
        spriteBatch.End();
        base.Draw(gameTime);
    }

Player class:

    Texture2D Guy;
    Point Position;
    public void LoadContent(ContentManager Content)
    {
        Guy = Content.Load<Texture2D>("Guy");
    }
    public void Update(GameTime gameTime)
    {
        Position = Mouse.GetState().Position;
    }
    public void Draw(SpriteBatch spriteBatch)
    {
        spriteBatch.Draw(Guy, Position.ToVector2(), Color.White);
    }

It just returns 0,0! What is the problem? Please help!

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 6821

Trending Articles