javascript - Using the mouse to control a game in HTML canvas - Stack Overflow

I am trying to find out if it is possible for JavaScript and HTML'sto take control of the mouse

I am trying to find out if it is possible for JavaScript and HTML's to take control of the mouse and introduce relative movement control - the type of mouse control you get in first person games (where the mouse can be moved in one direction and the player will infinitely turn until the mouse stops).

The only way I can think this could be achieved is by taking control of the mouse via JavaScript, which I'm sure is not possible. Does anyone have any ideas on this?

I am trying to find out if it is possible for JavaScript and HTML's to take control of the mouse and introduce relative movement control - the type of mouse control you get in first person games (where the mouse can be moved in one direction and the player will infinitely turn until the mouse stops).

The only way I can think this could be achieved is by taking control of the mouse via JavaScript, which I'm sure is not possible. Does anyone have any ideas on this?

Share Improve this question asked Dec 23, 2010 at 15:04 GregGreg 21.9k17 gold badges88 silver badges109 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

Good news old question, with the introduction of Mouse Lock, https://developer.mozilla/en/API/Mouse_Lock_API , you can capture relative movement.

Depending on what you are making you could do like flight sims. Meaning, the rate of change is determined by the distance of the mouse from the center/rest position, instead of the actual delta of the mouse. This only works well for vehicle games though.

Not really. You could simulate this: onmousemove, get X and Y coordinates, and calculate from this the cursor's position relative to your game viewport (e.g. if the game happens in a square from [100,100] to [200,200], then mouse at [59,92] means "turn left", as it's to the left of the game's "center" at [150,150]).

A possible problem: you stop receiving events once the mouse is outside the browser window (ask player to maximize window for best experience?).

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745102389a4611353.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信