画布:基于指针的视口/包含鼠标指针
似乎没有一个好的方法可以使 视口基于鼠标指针的位置并能够自由移动。基本上,就像市场上所有其他第一人称游戏一样。
- 没有办法捕获鼠标 在
元素内。
- 没有办法设置位置 的鼠标指针。
- 无法全屏显示 使用
,即使一旦到达边缘,功能也会被破坏。
也有充分的理由。想象一下恶意者可能(并且肯定会)采用什么可能的场景。
也许现在考虑一些几乎只在 3D 环境中有用的东西还为时过早,而且还没有规范。
您的采取或解决方案是什么?
There doesn't seem to be a good way to base the <canvas>
viewport on the location of the mouse pointer and being able to move around freely. Basically, like every other first-person game on the market.
- There is no way to capture the mouse
inside a<canvas>
element. - There is no way to set the position
of the mouse pointer. - It is not possible to go full screen
with<canvas>
, and even if, once the edge has been reached, functionality will be broken.
For good reasons, too. Imagine what possible scenarios could (and definitely would) be employed by malicious persons.
Perhaps it's too early to be thinking of something that is almost only of any use in a 3D environment, something that there isn't yet a spec for.
What's your take or solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以获取
画布
内的鼠标位置。深入了解 HTML5:让我们称之为绘图表面
You can get the mouse position inside of a
canvas
.From Dive Into HTML5: Let's Call it a Draw(ing Surface)
我认为对此没有一个好的解决方案——至少在我们获得鼠标锁定之前是这样。无论您的解决方案多么优雅,如果您制作了一个由鼠标外观驱动的抽搐游戏,用户将在某个时刻在画布区域之外抽搐。即使他们没有意外点击链接,当视图停止响应鼠标时,他们的沉浸感也会被破坏。
对于节奏较慢的游戏,您可以:
值得注意的是,Firefox 中有一个关于鼠标锁定的开放功能请求。但不幸的是,这个、鼠标隐藏或全屏都不是 WebGL 规范的一部分。
Unity 支持所有这些功能,因此如果您确实需要 FPS 控件,这可能是一个值得考虑的途径。
I don't think there is a good solution for this -- at least, not until we get mouse locking. No matter how elegant your solution, if you make a twitchy mouselook driven game, the user is going to twitch outside the canvas area at some point. Even if they don't accidentally click a link, their immersion will be broken when the view stops responding to their mouse.
For slower paced games, you could:
It's worth noting that there is an open feature request in Firefox for mouse locking. But, unfortunately, neither this, nor mouse hiding or fullscreen are part of the WebGL spec.
All of these features are supported by Unity, so that may be a path to look at if you really need FPS controls.