This is a read-only archive of the Framer Community on Facebook.

What is Framer? Join the Community
Return to index
David Phillips
Posted Oct 08 - Read on Facebook

Is there an easy way to maintain the relative position of a layer when changing it's superLayer? e.g. When importing a PSD, if I have a layer that's a few levels deep and I change its superLayer to the "root" level, how do I maintain it's x and y position? Currently, the superLayer changes, but the x and y pos stay what they were so the layer moves...


Arron J Hunt

add the superLayer's x/y to the layer's x/y? I'm not sure I understand your question.

David Phillips

Say there's a LayerA. LayerA is at y:10. LayerB is a subLayer of LayerA. LayerB is at y:50. If I change the superLayer for LayerB to be the same as that of LayerA, LayerB will be at y:50, when before it was essentially at y:60. So it appears to shift up by 10.

Obviously it's easy in this example to just set it's y to 60, but if it's nested 3-4 levels deep, not so much.

Arron J Hunt

Right, so the new y position for layerB would be layerA.y+layerB.y, also the same with x. Because really the actual offset of the subLayer is just its coordinates plus the coordinates of its superLayer

layerB.y += layerA.y

David Phillips

Yep. Flash used to have a helper function localToGlobal, which you could use in conjunction with analogous globalToLocal to do some of that translation for you. I was hoping that Framer had something similar.

Arron J Hunt

Should be pretty easy to build a function that could calculate it though :)

Andreas Wahlström

LayerB.screenFrame should help you here :)

David Phillips

Something like this works well so far:

changeSuperKeepPosition: (obj, newSuper) =>
tempFrame = obj.screenFrame
obj.superLayer = newSuper
return obj

Read the entire post on Facebook