我正在尝试将鼠标对象设置为通过速度而不是通过绝对位置工作。(虽然它同时跟踪两者,但 Velocity 是我想要更新它的方式。)
但是我遇到了一些问题。
首先,在窗口模式下,鼠标动作不正确。因为一旦它移出屏幕,鼠标就会消失。我尝试在每个 Update() 滴答声中使用 Mouse.SetPosition 将其设置为屏幕中心,并将其锁定到窗口。但是,这也会导致问题。
要查看实际问题,只需在此处编译 .sln -> https://github.com/redcodefinal/Clixel
一切都是自动的,因此您只需编译即可。ClxG 已经有一个 ClxMouse 对象。(ClxG.鼠标)
这是我正在研究的整个鼠标类。
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:如何在过程中将鼠标锁定到一个窗口而不爆炸整个世界?
我真的很感激任何帮助。