Skip to content

动作播放

149 words
1 min

获取动作组列表

ts
const model = await l2d.create({
  path: 'https://model.hacxy.cn/live2d_002_101/object_live2d_002_101.asset.model3.json',
  scale: 0.1
});
const motionGroups = model.getMotionGroupNames();
console.log(motionGroups);

根据动作组名称获取动作列表

ts
const model = await l2d.create({
  path: 'https://model.hacxy.cn/live2d_002_101/object_live2d_002_101.asset.model3.json',
  scale: 0.1,
});
const motionGroups = model.getMotionGroupNames();
console.log(motionGroups);
const motionNames = model.getMotionListByGroupName('Tap');
console.log(motionNames);

播放动作

随机播放

接下来我们可以使用上面的方法在1秒钟后从Tap动作组中随机播放一个动作:

ts
const model = await l2d.create({
  path: 'https://model.hacxy.cn/live2d_002_101/object_live2d_002_101.asset.model3.json',
  scale: 0.1,
});
const motionGroups = model.getMotionGroupNames();

model.showHitAreaFrames();

setTimeout(() => {
  model.playMotion(motionGroups[1]);
}, 1000);

指定播放

playMotion方法支持在第二个参数传入一个索引值, 来准确指定播放某个动作组的哪一个动作:

ts
const model = await l2d.create({
  path: 'https://model.hacxy.cn/live2d_002_101/object_live2d_002_101.asset.model3.json',
  scale: 0.1,
});
const motionGroups = model.getMotionGroupNames();

model.showHitAreaFrames();

setTimeout(() => {
  model.playMotion(motionGroups[1], 1);
}, 1000);

MIT Licensed