createImageFigure()
创建图片角色,支持 PixiJS 渲染和动画效果。
函数签名
createImageFigure(id: string, props: {
name: string;
path: string;
avatar?: string;
}): ImageFigure参数
| 参数 | 类型 | 描述 |
|---|---|---|
id | string | 角色唯一标识 |
name | string | 角色名称 |
path | string | 图片资源路径 |
avatar | string? | 头像路径(可选) |
基础用法
const qing = createImageFigure("qing", {
name: "秦",
path: "/figures/qing/qing.png",
avatar: "/avatars/qing.png",
});显示角色
// 定义常用的位置属性
const position = {
x: 849.56,
y: 5.66,
scaleX: 0.42,
scaleY: 0.42,
rotation: 0,
alpha: 1,
anchorX: 0,
anchorY: 0,
};
// 显示角色
qing.show(position);使用示例
// 显示并对话
qing.show(position);
qing.speak`你好!`;
// 动画效果
qing.bounce().speak`我会弹跳`;
qing.fadeOut().speak`我要消失了`;
qing.fadeIn();
// 切换图片
qing.switch("/figures/qing/qing_happy.png");
// 隐藏角色
qing.hide();可用方法
| 方法 | 描述 |
|---|---|
.speak() | 显示对话 |
.show(props?) | 显示角色 |
.hide() | 隐藏角色 |
.set(props) | 设置属性(无动画) |
.to(props, options?) | 补间动画 |
.switch(path) | 切换图片资源 |
.fadeIn() | 淡入 |
.fadeOut() | 淡出 |
.bounce() | 弹跳 |
.shake() | 抖动 |
PixiProperty 属性
| 属性 | 类型 | 描述 |
|---|---|---|
x | number | X 坐标 |
y | number | Y 坐标 |
scaleX | number | X 缩放 |
scaleY | number | Y 缩放 |
rotation | number | 旋转角度 |
alpha | number | 透明度 (0-1) |
anchorX | number | 锚点 X |
anchorY | number | 锚点 Y |
Last updated on