Mouse.SetPosition()赋值变量被视为无效

时间:2014-12-17 14:13:03

标签: c# xna xna-4.0

我试图将鼠标位置设置为等于变量" location"但是我收到了错误"无法隐式转换类型' void'到' Microsoft.Xna.Framework.Input.MouseState"。据我所知,#34; location"不是无效的。这是代码,由于试图使这项工作有点混乱:

class Player
{
    private Texture2D texture;
    private static int textureSize = 20;
    private static int screenWidth = Game1.Instance.GraphicsDevice.Viewport.Width;
    private static int screenHeight = Game1.Instance.GraphicsDevice.Viewport.Height;
    private static int halfTexture = (int)(textureSize * (screenHeight / (double)textureSize)) / 2;
    private Vector2 location;
    private Rectangle destination;
    private float speed;
    private MouseState mouse;

    public Player(Texture2D texture)
    {
        this.texture = texture;
        this.location = new Vector2(screenWidth / 2 - halfTexture, screenHeight * 3 / 4 - halfTexture);
        this.destination = new Rectangle((int)location.X, (int)location.Y, textureSize, textureSize);
        this.mouse = Mouse.SetPosition((int)location.X, (int)location.Y); // the error is here
    }

那么这里发生了什么,我该如何解决?

1 个答案:

答案 0 :(得分:1)

在没有查看XNA文档的情况下,我仍然可以安全地说Mouse.SetPosition - 方法返回void并且您正在尝试将其返回值分配给this.mouse输入MouseState。删除该任务,你会没事的。