Commit cb214a80 authored by Tt's avatar Tt

feat(play): 添加小鱼飞向水桶的动画效果

parent 89d42798
......@@ -971,6 +971,7 @@ export class PlayComponent implements OnInit, OnDestroy {
fish['child_image'].ref.visible = false;
fish['child_paopao_ani'].ref.visible = true;
this.createFlyingFish(fish);
// 按顺序切换序列帧 pao_pao_xu_lie_zhen_1 到 pao_pao_xu_lie_zhen_9
let currentFrame = 1;
const maxFrame = 9;
......@@ -991,6 +992,56 @@ export class PlayComponent implements OnInit, OnDestroy {
return fish;
}
/**
* 创建临时小鱼并飞向水桶
* @param fish 原始鱼对象
*/
createFlyingFish(fish) {
// 1. 获取小鱼的全局坐标
const xiao_yu = fish['child_xiao_yu'];
const fishGlobalX = fish.ref.x + xiao_yu.ref.x;
const fishGlobalY = fish.ref.y + xiao_yu.ref.y;
// 2. 创建一个临时小鱼
const tempFishId = `temp_fish_${Math.floor(Math.random() * 1000)}_${Date.now()}`;
const tempFish = this.g_cartoon.createCartoonElement(tempFishId, 'MySprite');
// 使用与原小鱼相同的图像
tempFish.ref.init(xiao_yu.ref.img);
tempFish.ref.scaleX = xiao_yu.ref.scaleX;
tempFish.ref.scaleY = xiao_yu.ref.scaleY;
// 设置临时小鱼的全局位置
tempFish.ref.x = fishGlobalX;
tempFish.ref.y = fishGlobalY;
// 3. 获取水桶的全局位置
const tong = this.cat_center['child_tong_left'];
const tongGlobalX = this.cat_center.ref.x + tong.ref.x;
const tongGlobalY = this.cat_center.ref.y + tong.ref.y;
// 将临时小鱼添加到舞台
this.render(tempFish.ref, zIndexMap.card + 1);
// 4. 创建小鱼飞向水桶的动画
tweenChange(
tempFish.ref,
{
x: tongGlobalX,
y: tongGlobalY,
scaleX: tempFish.ref.scaleX * 0.5, // 飞行过程中缩小
scaleY: tempFish.ref.scaleY * 0.5
},
0.8, // 动画时间
() => {
// 动画完成后移除临时小鱼
this.m_renderArr = this.m_renderArr.filter(item => item !== tempFish.ref);
tempFish.ref.visible = false;
},
TWEEN.Easing.Quadratic.Out // 使用缓动函数使动画更平滑
);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment