如何在 XNA 游戏中获得 IBeam 光标?
我已经设法让光标在一个简单的 XNA“游戏”中更改为 IBeam,更新为:
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// TODO: Add your update logic here
if (Keyboard.GetState().IsKeyDown(Keys.A))
{
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Arrow;
}
if (Keyboard.GetState().IsKeyDown(Keys.I))
{
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.IBeam;
}
base.Update(gameTime);
}
按下“I”时,鼠标更改为 IBeam 光标,但当您移动鼠标时,立即更改回箭头。有没有办法让它保持默认的 Windows IBeam,或者我需要创建和跟踪自定义光标?
[编辑] 我还应该指出,每帧设置光标都会导致鼠标移动时光标闪烁。似乎 XNA(或 Windows)在每帧内部将光标重置为箭头?
I've managed to get the cursor to change to an IBeam in a trivial XNA 'Game' with Update as:
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// TODO: Add your update logic here
if (Keyboard.GetState().IsKeyDown(Keys.A))
{
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Arrow;
}
if (Keyboard.GetState().IsKeyDown(Keys.I))
{
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.IBeam;
}
base.Update(gameTime);
}
The mouse changes to the IBeam cursor when 'I' is pressed, but immediately changes back to an arrow when you move the mouse. Is there a way to get it to stay as the default Windows IBeam, or will I need to create and track a custom cursor?
[EDIT] I should also point out that setting the cursor every single frame causes it to flicker when the mouse is moved. It seems the XNA (or Windows) is internally resetting the cursor to an arrow every frame?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在手动绘制之前,我会尝试设置底层 System.Windows.Forms.Form 的 Cursor 属性:
由于我现在没有安装 XNA,所以我不知道这是否可行,或者是否可行它将是永久性的,但我不明白为什么不会。
Before resorting to drawing it manually, I'd try to set the Cursor property of the underlying System.Windows.Forms.Form:
As I don't have XNA installed right now, I don't know if this will work, or if it will be permenant, but I don't see why it wouldn't.
听起来你必须手动绘制它。它应该不会太难 - 只需通过 SpriteBatch 在光标位置绘制一个精灵即可。
这是一些提取光标图像的代码。请记住,您将需要对 System.Drawing 的额外引用。
请记住,这不是我的想法 - 不能保证有效。不过,基本的想法就在那里。
Sounds like your going to have to draw it manually. It shouldn't be too hard - just draw a sprite via SpriteBatch at the location of the cursor.
And here's some code to extract the cursor image. Keep in mind you'll need an extra reference to System.Drawing.
Keep in mind this is off the top of my head - not guaranteed to work. The basic idea is there, though.