Name
SetLayerAnchor -- change anchor point of layer (V4.5)
Synopsis
SetLayerAnchor(id, ax, ay)
Function
This function can be used to change the anchor point of a layer. The anchor point is a point inside the layer that is used as the origin for all layer transformations (scale, rotate) and also the position of a layer is always relative to the anchor point. Sometimes the anchor point is also referred to as the 'hot spot' of a layer.

The anchor point can be any point inside the layer ranging from 0.0/0.0 (top left corner of the layer) to 1.0/1.0 (bottom right corner of the layer). The center of the layer would be defined by an anchor point of 0.5/0.5.

For example, if you want to have a layer that shall be rotated around its center point, then you need to set this layer's anchor point to 0.5/ 0.5. If it shall be rotated around its top left corner, you have to use 0.0/0.0 as the anchor point. To rotate around the layer's bottom right corner, use 1.0/1.0 as the anchor point. The usual setting is to rotate around the center, so you should normally set the anchor point to 0.5/0.5.

When using an anchor point different than 0.0/0.0, keep in mind that all position specifications will be relative to the anchor point now. This means that a position of 0:0 does not necessarily mean that the layer will appear at the top-left display corner. For example, if you have a layer with an anchor point of 1.0/1.0, moving this layer to position 0:0 (top left corner of display) would make the layer pretty much invisible because its anchor point is set to the bottom-right corner of the layer. Thus, if you move a layer with a bottom-right anchor point to position 0:0, it means that the bottom-right corner of the layer will actually appear at 0:0. This obviously means that only a single pixel of the layer will be visible. The rest will be off-screen.

By default, all layers will use an anchor point of 0.0/0.0.

Inputs
id
identifier of a layer
ax
x coordinate of anchor point; must be between 0.0 and 1.0
ay
y coordinate of anchor point; must be between 0.0 and 1.0
Example
EnableLayers
SetFillStyle(#FILLCOLOR)
Box(300, 200, 300, 200, #RED)
WaitLeftMouse
SetLayerAnchor(1, 0.5, 0.5)
WaitLeftMouse
SetLayerAnchor(1, 1.0, 1.0)
WaitLeftMouse
The code above demonstrates three different anchor points: First, at 0.0/0.0, then at 0.5/0.5, finally at 1.0/1.0. You can see that the layer will move with every call to SetLayerAnchor(). That is because the position of a layer is always relative to its anchor point. Thus, the layer will move although its position will always be 300:200.

Show TOC