Skip to content

脚本 API

Path (路径)

Rive 脚本中的路径操作 API。

概览

Path API 允许你在脚本中操作和查询路径数据。

访问路径

javascript
// 获取路径节点
const path = artboard.node("MyPath");

// 检查是否是路径
if (path.isPath) {
  // 执行路径操作
}

路径属性

javascript
// 获取路径长度
const length = path.length;

// 获取路径边界
const bounds = path.bounds;

路径操作

获取路径上的点

javascript
// 获取路径上某一位置的点 (0-1 范围)
const point = path.positionAt(0.5);
console.log("X:", point.x, "Y:", point.y);

获取切线

javascript
// 获取路径上某一位置的切线方向
const tangent = path.tangentAt(0.5);

使用场景

  • 沿路径动画对象
  • 计算路径交点
  • 动态修改路径形状

Vector APIMat2D API