Getting X and Y on the screen.

For questions about using Classic.

Post » Tue Feb 09, 2010 9:58 pm

Hello, i realized that when i get the X and Y of the mouse, it gives the point on the screen instead of the points in the game.
So i want to get the X and Y of an object by its points on the screen, is it possible?

The reason is:
I am trying to make an auto-target, so when i press the button X, the mouse cursor go to a target.
I cant make that by picking the X and Y of an object because the are different types of valors.
B
22
S
7
G
5
Posts: 90
Reputation: 3,430

Post » Tue Feb 09, 2010 10:19 pm

The built in expressions MouseX and MouseY give coordinates in the game.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Tue Feb 09, 2010 11:59 pm

[quote="Metal_X":1dmlvalv]I am trying to make an auto-target, so when i press the button X, the mouse cursor go to a target.[/quote:1dmlvalv]

You can't set the position of the mouse, if that's what you mean. The mouse sets the position of the mouse.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Wed Feb 10, 2010 12:07 am

[quote:67fqouzq]You can't set the position of the mouse, if that's what you mean. The mouse sets the position of the mouse.[/quote:67fqouzq]
But in the actions on events sheet theres a command to "Set mouse X" and "Set mouse Y" in the "MouseKeyboard" object Oo
B
22
S
7
G
5
Posts: 90
Reputation: 3,430

Post » Wed Feb 10, 2010 12:20 am

Whaaaa... :shock:

I have never noticed that action. Very strange! I learned something new today.

Anyway, it appears that it sets the coordinates according to your desktop and not according to your the game window. So I don't know of a really good method for using that the way you need it.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Wed Feb 10, 2010 12:34 am

You can use the Window object to get the position of the window and position the mouse accordingly.

Example

This positions the mouse to a randomly picked box. You'll probably have to add some things to account for screen scrolling -- if you need it -- but it shouldn't be to difficult.
Moderator
B
98
S
37
G
19
Posts: 1,584
Reputation: 17,817

Post » Fri Feb 12, 2010 5:24 am

Oh, thanks linkman, but i test on my project and its didnt work well...
Whats the difference between getting the ClientX and X of the window?

Do you think theres a different way to make that?
B
22
S
7
G
5
Posts: 90
Reputation: 3,430

Post » Fri Feb 12, 2010 10:41 am

ClientX returns the position of your game frame relative to the screen while the X position of the window is the position of the window from the top left including the title bar and border.

I suggest that you post a CAP file that we can take a look out so we can help with your problem.
Moderator
B
98
S
37
G
19
Posts: 1,584
Reputation: 17,817


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests