How do I keep my cursor within playing area

Get help using Construct 2

Post » Mon Jul 13, 2015 4:34 pm

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.
B
24
S
4
Posts: 78
Reputation: 1,308

Post » Mon Jul 13, 2015 8:35 pm

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.
My tutorial through development blog is at http://myconstruct2dev.blogspot.co.uk/
B
12
S
3
Posts: 221
Reputation: 1,328

Post » Mon Jul 13, 2015 9:04 pm

Thank You. I will check your link out.
B
24
S
4
Posts: 78
Reputation: 1,308

Post » Mon Jul 13, 2015 10:11 pm

@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
B
19
S
3
G
1
Posts: 29
Reputation: 1,038

Post » Mon Jul 13, 2015 10:18 pm

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

how-do-i-keep-my-cursor-with-an-area_t149725
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775


Return to How do I....?

Who is online

Users browsing this forum: darkrealos, luckyrawatlucky and 20 guests