How do I teleport my cursor?

Get help using Construct 2

Post » Thu Jun 29, 2017 8:16 am

Hey guys, I have game where i have to move my mouse.
But when i move mouse to layout's corner, it has to teleport to other, like "Warp" behavior.
How do i do this? Is there some plugins or other solutions? It can be sprite, not only mouse/cursor itself.
Thank you for reading, and sorry for my bad english :D
B
3
Posts: 6
Reputation: 197

Post » Wed Jul 05, 2017 3:44 pm

You can't do that for security reasons.
https://stackoverflow.com/a/4752512/2555197
https://www.ravenheart.ca/home
I don't check the forums much anymore, but I will receive an email for PMs.

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
23
S
6
G
1
Posts: 1,419
Reputation: 4,867

Post » Thu Jul 06, 2017 4:43 pm

Well now i can't make mouse support for my first person game.
B
3
Posts: 6
Reputation: 197

Post » Thu Jul 06, 2017 9:56 pm

You can simulate this by simulating a cursor, the result therefore only working within the game and circumventing the above security issue.

Add a Cursor sprite.
Have variables which track the X and Y of the Mouse. Call them MousePrevX & MousePrevY.
Every tick:
-> Set Cursor X to Self.X + ( Mouse.X - MousePrevX )
-> Set Cursor Y to Self.Y + ( Mouse.Y - MousePrevY )

Don't forget to use the Cursor's position rather than the Mouse's when judging things like what's being clicked on etc. Good luck!
<iframe frameborder="0" src="https://itch.io/embed/146124?linkback=true&dark=true" width="552" height="167"></iframe>
B
26
S
7
Posts: 254
Reputation: 2,389

Post » Fri Jul 07, 2017 9:39 am

mrtumbles wrote:You can simulate this by simulating a cursor, the result therefore only working within the game and circumventing the above security issue.

Add a Cursor sprite.
Have variables which track the X and Y of the Mouse. Call them MousePrevX & MousePrevY.
Every tick:
-> Set Cursor X to Self.X + ( Mouse.X - MousePrevX )
-> Set Cursor Y to Self.Y + ( Mouse.Y - MousePrevY )

Don't forget to use the Cursor's position rather than the Mouse's when judging things like what's being clicked on etc. Good luck!


Cursor object appears below mouse and nothing more happens
B
3
Posts: 6
Reputation: 197

Post » Fri Jul 07, 2017 11:39 am

Try teleporting the cursor.

Don't post again without a CapX.
<iframe frameborder="0" src="https://itch.io/embed/146124?linkback=true&dark=true" width="552" height="167"></iframe>
B
26
S
7
Posts: 254
Reputation: 2,389

Post » Fri Jul 07, 2017 11:41 am

Oh, I did forget a step: after you've set the position of the Cursor, set the Mouse.PrevX/Y to Mouse.X/Y
<iframe frameborder="0" src="https://itch.io/embed/146124?linkback=true&dark=true" width="552" height="167"></iframe>
B
26
S
7
Posts: 254
Reputation: 2,389

Post » Fri Jul 07, 2017 11:42 am

And since your English is bad I'd recommend a 'thank you' is customary when someone volunteers help :)
<iframe frameborder="0" src="https://itch.io/embed/146124?linkback=true&dark=true" width="552" height="167"></iframe>
B
26
S
7
Posts: 254
Reputation: 2,389

Post » Fri Jul 07, 2017 2:53 pm

It works, but now, when mouse hits the border nothing happens. That was the main problem ;/
B
3
Posts: 6
Reputation: 197

Post » Fri Jul 07, 2017 3:08 pm

Post a CapX, this will make it much easier for people to diagnose and solve your problem.
<iframe frameborder="0" src="https://itch.io/embed/146124?linkback=true&dark=true" width="552" height="167"></iframe>
B
26
S
7
Posts: 254
Reputation: 2,389

Next

Return to How do I....?

Who is online

Users browsing this forum: burak22, kelany, plinkie and 5 guests