[FIX] True Mouse.X/Mouse.Y for Layout Scale

Bugs will be moved here once resolved.

Post » Wed May 30, 2012 11:16 am

Hi,

I had a problem with the way Construct 2 handles Mouse.X/Mouse.Y layout coordinates when scaling the layout. After some time I finally figured out a solution to this problem.

To convert the correct mouse position from the incorrect mouse position on a layoutscale that is not 100% you have to..

[System | Every Tick]
True Mouse.X = (Mouse.AbsoluteX-WindowWidth/2)/LayoutScale+Scrollx
True Mouse.Y = (Mouse.AbsoluteY-WindowHeight/2)/LayoutScale+Scrolly

I also have a HTML5 link and a *.capx file showing this.

HTML 5
*.CAPX

The Blue Circle is Construct 2's Mouse.X/Mouse.Y position..
The Green Circle is the True Mouse.X/Mouse.Y position.

I hope this helps :)
B
10
S
2
Posts: 20
Reputation: 1,258

Post » Wed May 30, 2012 12:20 pm

I think you're just missing the layer versions of the mouse X/Y expressions. From Mouse in the manual:

[quote]X("layer")
Y("layer")

Return the position of the mouse cursor in game co-ordinates, with scrolling, scaling and rotation taken in to account for the given layer. The layer can be identified either by a string of its name or its zero-based index (e.g. Mouse.X(0)).[/quote]
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Wed May 30, 2012 12:41 pm

They don't work when scaling a layout not the layer. Try it out yourself. :)

This is a solution for getting the correct Mouse.X/Mouse.Y positions when scaling the layout not the layers.

Could you please include this in your next version as an expression such as..

TrueMouse.X
TrueMouse.Y

or even just replace your current ones with this.

BTW this should also solve your problems with layer scaling so you will have no need for a separate layer for the mouse.michelangelo2012-05-30 12:46:36
B
10
S
2
Posts: 20
Reputation: 1,258

Post » Thu May 31, 2012 3:00 pm

@michelangelo, the mouse layer expressions do also take in to account the layout scale (which implicitly alters all layer scales). I tried modifying your example to use the mouse layer expressions and it worked OK, have you tried it?
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Sun Sep 27, 2015 12:30 am

thank you for this. it's beautiful!!!
B
14
S
4
Posts: 21
Reputation: 1,038


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 1 guest