Convert sprite coordinates from one layer to another

Get help using Construct 2

Post » Thu Aug 07, 2014 2:25 am

I want to convert the X and Y coordinates of a sprite on a layer which has 100% parallax to a layer that has 0% parallax and still appear to be in the same position.

Please note, I'm using fullscreen inner scaling and thus the expression LayerToCanvas doesn't work because the canvas is scaled to some unknown degree and so the coordinates will be different for every screen size.
B
151
S
75
G
20
Posts: 1,793
Reputation: 22,749

Post » Thu Aug 07, 2014 3:32 am

I really don't know the answer, but would maybe having an invisible sprite already on the other layer work?
B
88
S
43
G
71
Posts: 601
Reputation: 43,669

Post » Thu Aug 07, 2014 1:54 pm

I think what you're looking for is sprite.x("layername")
Moderator
B
95
S
34
G
33
Posts: 3,007
Reputation: 27,876

Post » Fri Aug 08, 2014 12:45 am

Hey @arima, I think that works for the Mouse object, but I don't think it works for sprites.

I found a reasonable solution though, it involves creating an "anchor", which is a sprite with the anchor behaviour on a layer you want that is set at pos: 100,100. This is used to determine the scale of the canvas, if we turn it into a percentage:

100/LayerToCanvas X("Layer",anchor.X,anchor.Y)

This will give something like 70 or 100% depending on monitor size, so you can multiply this to other uses of LayerToCanvas to make it consistent across all displays, I just jumble it all together though:

(100/LayerToCanvas X("Layer",anchor.X,anchor.Y))*LayerToCanvas X("Layer",sprite.X,sprite.Y)
B
151
S
75
G
20
Posts: 1,793
Reputation: 22,749

Post » Fri Aug 08, 2014 2:38 am

Clever solution. Just might come in handy for me in the near future.
Thanks for sharing!
B
88
S
43
G
71
Posts: 601
Reputation: 43,669

Post » Sat Sep 20, 2014 11:56 am

I had this same problem and made tutorial about how I did it.
https://www.scirra.com/tutorials/1167/layertocanvascanvastolayer-example
B
34
S
9
G
3
Posts: 517
Reputation: 5,246


Return to How do I....?

Who is online

Users browsing this forum: dop2000, FilmosYT, Governador, TRMG and 11 guests