NarraLeaf

变换

Transform 类的动画方法与 commit 分组机制

Transform 描述可显示元素在屏幕上的变化:位置、缩放、旋转、透明度,以及应用的视觉效果

当动画有多个步骤,或同一段动画需要复用时,可以使用 Transform

import { Transform } from "narraleaf-react";

const bounce = Transform.create()
    .position({ yoffset: -10 })
    .commit({ duration: 120, ease: "easeOut" })
    .position({ yoffset: 0 })
    .commit({ duration: 100, ease: "easeOut" })
    .repeat(2);

scene.action([
    characterImage.transform(bounce),
]);

页面

commit() 如何组合变化

添加属性

需要同时变化的属性,都写在同一个 commit()

Transform.create()
    .position({ xalign: 0.5 })
    .zoom(1.1)
    .opacity(1)

提交一次

一次 commit() 会把前面的属性调用合成一个动画步骤。下面的例子里,位置、缩放和透明度会同时变化

Transform.create()
    .position({ xalign: 0.5 })
    .zoom(1.1)
    .opacity(1)
    .commit({ duration: 300, ease: "easeOut" })

继续下一步

commit() 之后的属性调用属于下一段动画

Transform.create()
    .position({ xalign: 0.35 })
    .opacity(1)
    .commit({ duration: 300, ease: "easeOut" })
    .position({ xalign: 0.65 })
    .opacity(0.8)
    .commit({ duration: 300, ease: "easeInOut" })

完整属性类型见 TransformDefinitions

本页目录