Difference between CanvasToLayerX / Y and Mouse.X / Mouse.Y

Discussion and feedback on Construct 2

Post » Sat Nov 01, 2014 7:58 pm

What is the difference between these expressions:

CanvasToLayerX("Layer 0", Mouse.AbsoluteX, Mouse.AbsoluteY)

and

Mouse.X("Layer 0")

?

I was using these in a large (like 10,000 x 10,000 px field) zoom and pan, and they behave much differently, despite the fact that they seem conceptually the same.
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
22
S
6
G
1
Posts: 1,418
Reputation: 4,830

Post » Sun Nov 02, 2014 7:00 pm

Nobody knows how either of these work?
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
22
S
6
G
1
Posts: 1,418
Reputation: 4,830

Post » Sun Nov 02, 2014 9:51 pm

To be totally honest, I'm also waiting for someone who understands what the mouse.absolute(x/y) expression does in practice to answer this!
composer - multimedia artist
www.eli0s.com/en/
B
69
S
27
G
6
Posts: 1,146
Reputation: 10,379

Post » Mon Nov 03, 2014 4:11 pm

I use it in practice, and as far as I can determine it gives the mouse coordinate in a local layer. For instance, I have a 10,000 x 10,000 (roughly) pixel canvas that I zoom in on. The Mouse.absoluteX and Mouse.absoluteY give you the mouse coordinates with respect to the screen. Mouse.X("layer") and Mouse.Y("layer") gives me the mouse coordinates with respect to my 10,000 x 10,000 px grid.

I am not really certain at all how the other expression works or what canvas it is mapping from. I assume it is mapping from the c2canvas to whatever layer I specify, but I don't see why it needs both x and y coordinates to do that.
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
22
S
6
G
1
Posts: 1,418
Reputation: 4,830

Post » Mon Nov 03, 2014 4:55 pm

It should be the same as far as I can tell. Have you got an example where they give different values?
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,650

Post » Mon Nov 03, 2014 6:03 pm

B
34
S
9
G
3
Posts: 517
Reputation: 5,226

Post » Mon Nov 03, 2014 11:08 pm

Sort of. I am actually using it for a mouse-wheel-based zoom and pan (like Google maps) sort of thing.

I mostly want to know how that particular function works on the inside.
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
22
S
6
G
1
Posts: 1,418
Reputation: 4,830

Post » Tue Nov 04, 2014 12:24 am

I think they are identical. When you give a layer name to Mouse.X/Y, it does the same math as canvastolayer.
Scirra Founder
B
398
S
236
G
88
Posts: 24,428
Reputation: 194,600

Post » Tue Nov 04, 2014 2:57 am

What math is that though?

Why does it require a y-component for the X layer and an x-component for the Y layer though? That seems intuitively odd.

Either way, using the CanvasToLayerX/Y fixed (or at least markedly improved) our spastic zoom and pan problem over using the Mouse.X and Mouse.Y.

I suppose it would be nice to have more precise and thorough documentation, although I would much prefer Scirra improving Construct into the website design arena over improved documentation.
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
22
S
6
G
1
Posts: 1,418
Reputation: 4,830

Post » Tue Nov 04, 2014 5:06 am

My guess is x and y are needed if The layout or layer is rotated. If you really want to see the math you can look at the js files in the exporter directory of the C2 install.

The manual covers what the mouse expressions do pretty well imo:
https://www.scirra.com/manual/114/mouse
Mouse expressions

AbsoluteX
AbsoluteY
Return the position of the mouse cursor over the canvas area in the HTML page. This is (0, 0) at the top left of the canvas and goes up to the window size. It is not affected by any scrolling or scaling in the game.

X
Y
Return the position of the mouse cursor in game co-ordinates. This is (0, 0) at the top left of the layout. It changes to reflect scrolling and scaling. However, if an individual layer has been scrolled, scaled or rotated, these expressions do not take that in to account - for that case, use the layer versions below.

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)).


https://www.scirra.com/manual/126/system-expressions
Layers

In expressions where a layer is required, either its name (as a string) or index (as a number, zero-based) can be entered.

CanvasToLayerX(layer, x, y)
CanvasToLayerY(layer, x, y)
Calculate the layout co-ordinates underneath a position in canvas co-ordinates for a given layer.

LayerToCanvasX(layer, x, y)
LayerToCanvasY(layer, x, y)
Calculate the canvas co-ordinates above a position in layout co-ordinates for a given layer.


I'm curious in what ways you'd like it to be improved?
B
92
S
32
G
109
Posts: 5,291
Reputation: 70,993

Next

Return to Construct 2 General

Who is online

Users browsing this forum: didakcode, Tjums and 9 guests