Contain mouse to Layout

Get help using Construct 2

Post » Sun Nov 03, 2013 8:59 am

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?
B
6
S
1
Posts: 14
Reputation: 566

Post » Sun Nov 03, 2013 10:08 am

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.
B
241
S
63
G
33
Posts: 903
Reputation: 40,729

Post » Sun Nov 03, 2013 12:12 pm

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 :)nimos1002013-11-03 12:17:04
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Sun Nov 03, 2013 1:17 pm

@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.
B
6
S
1
Posts: 14
Reputation: 566

Post » Sun Nov 03, 2013 1:45 pm

Hmmm cant you just force fullscreen in browser?
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Sun Nov 03, 2013 2:56 pm

Or have it pause when it loses focus.

Which is in the main project properties.
B
241
S
63
G
33
Posts: 903
Reputation: 40,729


Return to How do I....?

Who is online

Users browsing this forum: lemonizer and 2 guests