.to()
补间动画,从当前状态平滑过渡到目标状态。基于 GSAP 实现。
函数签名
to(target: PixiProperty, options?: GsapOptions): Figure基础用法
// 移动到指定位置
figure.to({ x: 500, y: 200 });
// 改变透明度
figure.to({ alpha: 0.5 });
// 缩放
figure.to({ scaleX: 1.5, scaleY: 1.5 });动画选项
figure.to(
{ x: 500 },
{
duration: 1, // 持续时间(秒)
ease: "power2.out", // 缓动函数
delay: 0.5, // 延迟(秒)
}
);GsapOptions
| 属性 | 类型 | 描述 |
|---|---|---|
duration | number | 动画持续时间(秒) |
ease | string | 缓动函数 |
delay | number | 延迟时间(秒) |
常用缓动函数
| 缓动 | 效果 |
|---|---|
"none" | 线性 |
"power1.out" | 缓出 |
"power2.out" | 强缓出 |
"elastic.out" | 弹性 |
"bounce.out" | 弹跳 |
链式调用
// 移动后说话
figure.to({ x: 500 }).speak`我移动了`;
// 组合动画
figure.to({ x: 500 }).to({ alpha: 0.5 });中断支持
动画可被 interrupt 事件中断,中断时会跳到最终状态。
Last updated on