how to set the mouse cursor position in in-game coordinates

Post your own tutorials, guides and demos.

Post » Sat Jul 17, 2010 1:04 pm

setting the mouse cursor where you want it isn't as simple as setting mousex and mousey with mouse/keyboard. those actions set the cursor to screen coordinates, meaning the coordinates on your monitor, which have nothing to do with the game.

to set the mouse coordinates to a spot in your game, you need to take into account where the window is on the screen, how far into your layout you are scrolled, and how zoomed in you are. there is a formula you can use, and it's demonstrated in the following cap:
[url:2frwjuqi]http://dl.dropbox.com/u/1013446/mouseset.cap[/url:2frwjuqi]
when you run the cap, mousewheel zooms in and out, and since your mouse is hijacked and you can't reach the close button, hit escape to exit
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Sun Jul 18, 2010 12:51 am

Very nice. To help me understand this a little better, would you mind me asking the difference between "Window.ClientX" as apposed to "Window.X"? I noticed the results were a hair off when I switched them, but it was pretty much the same.
B
3
S
1
G
2
Posts: 57
Reputation: 964

Post » Sun Jul 18, 2010 1:16 am

[quote="greyspot":1pasu43x]Very nice. To help me understand this a little better, would you mind me asking the difference between "Window.ClientX" as apposed to "Window.X"? I noticed the results were a hair off when I switched them, but it was pretty much the same.[/quote:1pasu43x]
Window.X gets the position of the window including the border and title bar, while Window.ClientX gets the position of the content of the window, which excludes the border.
Moderator
B
98
S
36
G
19
Posts: 1,584
Reputation: 17,717

Post » Sun Jul 18, 2010 1:26 am

[quote="linkman2004":11icdp22]
Window.X gets the position of the window including the border and title bar, while Window.ClientX gets the position of the content of the window, which excludes the border.[/quote:11icdp22]

I see, thanks!
B
3
S
1
G
2
Posts: 57
Reputation: 964


Return to Your tutorials & example files

Who is online

Users browsing this forum: No registered users and 1 guest