0

I am developing a simple 2d game where a user has to point a gun at different objects and shoot them. When a user moves his mouse, the crosshair's position always stays the same, but the environment (all other objects) move, creating an effect of a crosshair moving. The problem is, when a cursor leaves the div (where all of the above happens), everything stops moving.

So, the question is: how can I make the cursor never leave the div (with a game) unless the game is paused?

Example of what I expect: link. In this game, when a user's playing, their cursor is always inside a game screen, but when he's in the menu or the game is paused, their cursor can leave a game screen.

tkachas
  • 1
  • 1
  • what happens if a user wants to close the tab? or do they have to pause to be able to close the browser? Maybe take a look here to see if it helps: https://stackoverflow.com/questions/51985774/js-prevent-mouse-from-leaving-screen – Spangle Dec 02 '22 at 04:54
  • @Spangle, That's actually kinda helpful. Thanks! – tkachas Dec 02 '22 at 05:12
  • Does this answer your question? [Keep mouse inside a div](https://stackoverflow.com/questions/5730433/keep-mouse-inside-a-div) – keikai Dec 02 '22 at 09:48
  • Hi and welcome to Stackoverflow, please take a lot at [Stackoverflow Tour Guide](https://stackoverflow.co/teams/features/?upgrade=true) to take an idea about how to write a good post – sohaieb azaiez Dec 02 '22 at 11:12

0 Answers0