过渡效果
了解 Pixi’VN 中用于显示和移除 canvas 组件的内置过渡效果,包括溶解、淡入淡出、移动、推动和缩放过渡。 了解如何自定义或创建自己的过渡效果,以在你的游戏流程中实现高级视觉效果。
Pixi’VN 提供了多种过渡效果,用于显示或移除canvas 组件,同时也支持创建你自己的过渡效果。
自定义功能
Pixi’VN 团队欢迎大家提出新的建议并做出贡献,让这个库变得更加完善。 欢迎在下方聊天区分享或提出你的过渡效果建议!
创建你自己的过渡效果很简单:使用 canvas.animate 来定义自定义效果。
为了帮助你入门,这里提供了 showWithDissolve 的简化版本:
import { canvas, ImageSprite, UPDATE_PRIORITY } from "@drincs/pixi-vn";
import { AnimationOptions } from "@drincs/pixi-vn/motion";
export default async function showWithDissolve(
alias: string,
component: ImageSprite,
props: AnimationOptions = {},
priority?: UPDATE_PRIORITY,
): Promise<string[] | undefined> {
let { completeOnContinue = true, ...options } = props;
// add the new component
canvas.add(alias, component);
// edit the properties of the new component
component.alpha = 0;
// create the ticker and play it
let id = canvas.animate(
alias,
{
alpha: 1,
},
{
...options,
completeOnContinue,
},
priority,
);
// load the image if the image is not loaded
if (component.haveEmptyTexture) {
await component.load();
}
// return the ids of the tickers
if (id) {
return [id];
}
}替换或移除之前的组件
如果已经存在具有相同 alias 的组件,你可以让它被替换,或者: