Contain mouse to Layout

0 favourites
  • 6 posts
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • In my game you control the player with the mouse. You can only move left and right and shoot.

    So I have code like this:

    Player.y = 400

    Every tick:

    Player.x = mouse.x

    But what a lot of my play testers do in their enthusiasm is move the mouse to far, and thus get out of the layout. When this happens you can no longer shoot or move, witch most of the time lead to death.

    I wanted to fix this by adding code like:

    Every tick:

    Mouse.y = 400

    if mouse.x < 0 mouse.x = 0

    if mouse.x > 640 mouse.x = 640

    But you can't set the mouse coordinates.

    Is there an other way to make sure you don't click outside of the layout?

  • I don't believe the browsers allow that, because unscrupulous app makers could lock peoples cursors in the window.

    You could make a sprite that follows the mouse and lock it to the screen, when the mouse went out, it would stick at the edge.

  • Not sure if it works, but you could try something:

    If mouse.x < 50 set mouse.x to 50

    If mouse.x > windowswidth - 50 set mouse.x = windowswidth - 50

    But no clue if that works :)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Paradox, That makes sense.

    I can make the player stay on screen that way, but it does not solve the problem that you easily click outside of the layout and loose focus :)

    nimos100, that is what I was thinking, but you can not set the mouse coordinates in CS2.

  • Hmmm cant you just force fullscreen in browser?

  • Or have it pause when it loses focus.

    Which is in the main project properties.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)