用户:
LH233查看:0 回复:3 评论:0 创建时间:2023-04-09T11:57:57
//先从模型库搜索"电梯"的模型, 并把它拖入场景中
const elevator = world.querySelector('#电梯-1') //获取电梯板实体
elevator.fixed = true//不受外力影响
elevator.collides = true//允许碰撞
const startPos = [喵, 11, 喵]//电梯的最低位置
const endPos = [喵, 50, 喵]//电梯的最高位置
const ani = elevator.animate([// 1+5+1+2=9, 总时间15秒被切成9份
{ position: startPos, duration: 1 },// 1/9 的时间停留在地面
{ position: startPos, duration: 5 },// 5/9 的时间用于地面往楼顶移动
{ position: endPos, duration: 1 },// 1/9 的时间停留在楼顶
{ position: endPos, duration: 2 },// 2/9 的时间从楼顶回到地面
], {
duration: 16 * 15, //播放一个循环共用时15秒,
iterations: 1,//动画只播放1次
direction: Box3AnimationDirection.WRAP,//让动画实体从终点回到起点
})
ani.onReady(() => {//当动画开始播放时
world.say('电梯准备启动')
})
ani.onFinish(() => {//当动画结束播放时
world.say('电梯自己停了')
})
world.onPress(({ button }) => {
if (button === Box3ButtonType.ACTION0) {//左键重新播放动画
ani.play({
duration: 16 * 15, //播放一个循环共用时15秒(每秒16帧),
iterations: Infinity,//动画无限次循环播放
direction: Box3AnimationDirection.WRAP,//让动画实体从终点回到起点
})
}
else if (button === Box3ButtonType.ACTION1) {//右键停止动画
ani.cancel()
}
})