节点只读数据(NodeReadData)
表示层级中的节点(Node),提供变换属性以及父/子节点访问能力。
字段(Fields)
position
节点本地位置(local position)。
rotation
节点本地旋转(弧度,radians)。
scale
节点本地缩放(local scale)。
worldTransform
节点世界变换(world transform)。
x
本地位置 x 坐标。
y
本地位置 y 坐标。
scaleX
本地缩放 x 分量。
scaleY
本地缩放 y 分量。
paint
路径效果所作用的描边或填充,来自其 update 收到的节点;否则为 nil。与 asPaint 相同。
function update(self: MyEffect, path: PathData, node: NodeReadData): PathData
local paint = node.paint
if paint then
print(paint.color)
end
return path
end
方法(Methods)
asPath
当节点是 Path 时,返回 PathData。
asPaint
返回路径效果所作用的描边或填充,来自其 update 收到的节点;否则为 nil。
function update(self: MyEffect, path: PathData, node: NodeReadData): PathData
local paint = node:asPaint()
if paint then
print(paint.thickness)
end
return path
end
bounds
bounds() -> (Vector, Vector)
节点在自身局部空间中的盒子,以最小点和最大点表示:布局的盒子、形状、路径或图像的范围、文本的布局盒子,以及嵌套画板所显示的画板。自身没有尺寸的节点(例如组或骨骼)两个点都是零。
if self.instance then
local button = self.instance:node('Button')
if button then
local min, max = button:bounds()
print(max.x - min.x, max.y - min.y)
end
end
worldBounds
worldBounds() -> (Vector, Vector)
节点在其画板空间中的盒子:bounds 经过世界变换后,它所覆盖区域的最小点和最大点。自身没有尺寸的节点只覆盖它的原点。
if self.instance then
local menu = self.instance:node('Menu')
if menu then
local min, max = menu:worldBounds()
local p = Vector.xy(120, 40)
print(p.x >= min.x and p.x <= max.x and p.y >= min.y and p.y <= max.y)
end
end