How do I keep my cursor within playing area

0 favourites
  • 5 posts
From the Asset Store
Mouse cursor is something that the player controls and sees all the time, that's why it is so important to make it cool!
  • Hi,

    I currentlly have my player follow toward my cursor.

    I like to know how I can tell my cursor to stay within the bottom 1/3 of the screen and not go outside.

    I am making a vertical scroller.

    Thank You.

  • The way I have done this is every tick, I check whether the cursor is in the right area or not. If it is, I store that in instance variables which are "last known good position". If it is not in the right area, I set the position from the last known good position. If you have a look at my centipede game (see URL below) this has exactly this - in Centipede (it's a 1980s arcade game) the player can move anywhere in about the bottom 1/4 or so of the screen - so things like layout constraints won't do. Though you can use a layout constraint for the other three sides, as it is only the upper boundary that is odd.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank You. I will check your link out.

  • paulscottrobson The problem with that would be that if the user moved the cursor above the "good" area - in this case the bottom 1/3 of the screen - then the player object would just stay in that position, not following the cursor sideways-wise. If the user then moved the mouse to the other side of the screen, then back down into the good area, the player would "teleport" to the cursor's position. That could be a game-breaking issue, especially if the player object teleported through an object it's not supposed to touch, basically allowing the user to cheat at the game.

    A different way to do it would be to set the player's position to the cursor's position, but clamped to the bottom 1/3 of the screen. This would not make the player able to teleport. Details on the "clamp" expression are found here, under "values" near the bottom of the page: https://www.scirra.com/manual/126/system-expressions

  • Just adjust the values of the capx provided in your other topic..

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