我想通過速度而不是通過絕對位置來設置鼠標對象。 (雖然它跟蹤兩者,但速度是我想要更新它的方式。)C#XNA鼠標移動速度?
但是我遇到了一些問題。
首先,在窗口模式下,鼠標不能正確操作。因爲一旦它脫離屏幕鼠標假髮了。我嘗試使用Mouse.SetPosition每Update()打勾將其設置爲屏幕的中心,將其鎖定到窗口。但是這也會導致問題。
在行動中看到剛剛編譯這裏的.sln問題 - >https://github.com/redcodefinal/Clixel
一切都是自動的,因此所有你需要做的只是編譯。 ClxG已經有一個ClxMouse對象。 (ClxG.Mouse)
這是我正在使用的整個Mouse類。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace org.clixel
{
public class ClxMouse : ClxSprite
{
private MouseState _curmouse, _lastmouse;
private int _scrollwheel;
public bool LeftDown
{
get
{
if (_curmouse.LeftButton == ButtonState.Pressed)
return true;
else
return false;
}
set { }
}
public bool RightDown
{
get
{
if (_curmouse.RightButton == ButtonState.Pressed)
return true;
else
return false;
}
set { }
}
public bool MiddleDown
{
get
{
if (_curmouse.MiddleButton == ButtonState.Pressed)
return true;
else
return false;
}
set { }
}
public bool LeftPressed
{
get
{
if (_curmouse.LeftButton == ButtonState.Pressed && _lastmouse.LeftButton == ButtonState.Released)
return true;
else
return false;
}
set { }
}
public bool RightPressed
{
get
{
if (_curmouse.RightButton == ButtonState.Pressed && _lastmouse.RightButton == ButtonState.Released)
return true;
else
return false;
}
set { }
}
public bool MiddlePressed
{
get
{
if (_curmouse.MiddleButton == ButtonState.Pressed && _lastmouse.MiddleButton == ButtonState.Released)
return true;
else
return false;
}
set { }
}
public MouseState CurMouse
{
get
{
return _curmouse;
}
set { }
}
public MouseState LastMouse
{
get
{
return _lastmouse;
}
set { }
}
public ClxMouse()
: base(ClxAssets.Textures.Cursor)
{
_curmouse = Mouse.GetState();
_lastmouse = _curmouse;
CollisionBox = new Rectangle(ClxG.Screen.X/2, ClxG.Screen.Y/2, Texture.Width, Texture.Height);
this.Solid = false;
Mouse.SetPosition(CollisionBox.X, CollisionBox.Y);
}
public ClxMouse(Texture2D _texture)
: base(_texture)
{
_curmouse = Mouse.GetState();
_lastmouse = _curmouse;
CollisionBox = new Rectangle(ClxG.Screen.Center.X, ClxG.Screen.Center.Y, Texture.Width, Texture.Height);
}
public override void Update()
{
_lastmouse = _curmouse;
_curmouse = Mouse.GetState();
Velocity = new Vector2(_curmouse.X - _lastmouse.X, _curmouse.Y - _lastmouse.Y);
Console.WriteLine(Velocity.ToString());
base.Update();
}
}
}
TLDR:如何在不爆炸整個世界的情況下將鼠標鎖定到窗口?
我真的很感激任何幫助。