Commit c1fb0ca2 authored by Tt's avatar Tt

fix(play): 修复鱼点击事件未正确注销的问题

parent 4862c365
......@@ -981,13 +981,14 @@ export class PlayComponent implements OnInit, OnDestroy {
}
createFish(type, data) {
const fishId = `fish_${Math.floor(Math.random() * 1000)}_${Date.now()}`
// 创建鱼元素
const fishId = `fish_${Math.floor(Math.random() * 1000)}_${Date.now()}`
const fish = this.g_cartoon.createCartoonElement(fishId, 'MySprite');
fish.ref.init(this.g_cartoon.images.get('fish'));
fish.ref.scaleX = this.g_mapScale;
fish.ref.scaleY = this.g_mapScale;
fish.fishId = fishId;
fish.ref.width = localImagesSize['pao_pao_da_png'].width * this.g_mapScale;
fish.ref.height = localImagesSize['pao_pao_da_png'].height * this.g_mapScale;
......@@ -1116,6 +1117,9 @@ export class PlayComponent implements OnInit, OnDestroy {
fish['child_image'].ref.visible = false;
fish['child_paopao_ani'].ref.visible = true;
// 注销该鱼的点击事件
this.unsubscribeFishEvent(fish.fishId);
// 创建飞向水桶的小鱼动画
this.createFlyingFish(fish);
this.brokePaopaoAni(fish);
......@@ -1757,6 +1761,17 @@ export class PlayComponent implements OnInit, OnDestroy {
this.updateFish();
}
/**
* 注销鱼的点击事件
* @param fishId 鱼的唯一标识符
*/
unsubscribeFishEvent(fishId) {
// 从按下事件队列中删除该鱼的点击事件
if (this.m_mapDownQueue[fishId]) {
delete this.m_mapDownQueue[fishId];
}
}
/**
* 清空所有鱼
* 移除所有当前屏幕上的鱼元素
......@@ -1765,6 +1780,8 @@ export class PlayComponent implements OnInit, OnDestroy {
// 从渲染对象数组中移除所有鱼
for (let i = this.m_fishArray.length - 1; i >= 0; i--) {
const fish = this.m_fishArray[i];
// 注销该鱼的点击事件
this.unsubscribeFishEvent(fish.fishId);
// 从渲染对象数组中移除
this.m_renderObject = this.m_renderObject.filter(item => item.element !== fish.ref);
}
......@@ -1838,6 +1855,8 @@ export class PlayComponent implements OnInit, OnDestroy {
// 如果鱼游出了屏幕左侧,从数组中移除
if (fish.ref.x < -fish.ref.width * fish.ref.scaleX / 2) {
// 注销该鱼的点击事件
this.unsubscribeFishEvent(fish.fishId);
// 从渲染对象数组中移除
this.m_renderObject = this.m_renderObject.filter(item => item.element !== fish.ref);
// 重新构建渲染数组
......
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