Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
SSIWB2504
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
template admin
SSIWB2504
Commits
c1fb0ca2
Commit
c1fb0ca2
authored
Aug 08, 2025
by
Tt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(play): 修复鱼点击事件未正确注销的问题
parent
4862c365
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
2 deletions
+21
-2
play.component.ts
src/app/play/play.component.ts
+21
-2
No files found.
src/app/play/play.component.ts
View file @
c1fb0ca2
...
@@ -981,13 +981,14 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -981,13 +981,14 @@ export class PlayComponent implements OnInit, OnDestroy {
}
}
createFish
(
type
,
data
)
{
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
'
);
const
fish
=
this
.
g_cartoon
.
createCartoonElement
(
fishId
,
'
MySprite
'
);
fish
.
ref
.
init
(
this
.
g_cartoon
.
images
.
get
(
'
fish
'
));
fish
.
ref
.
init
(
this
.
g_cartoon
.
images
.
get
(
'
fish
'
));
fish
.
ref
.
scaleX
=
this
.
g_mapScale
;
fish
.
ref
.
scaleX
=
this
.
g_mapScale
;
fish
.
ref
.
scaleY
=
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
.
width
=
localImagesSize
[
'
pao_pao_da_png
'
].
width
*
this
.
g_mapScale
;
fish
.
ref
.
height
=
localImagesSize
[
'
pao_pao_da_png
'
].
height
*
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 {
...
@@ -1116,6 +1117,9 @@ export class PlayComponent implements OnInit, OnDestroy {
fish
[
'
child_image
'
].
ref
.
visible
=
false
;
fish
[
'
child_image
'
].
ref
.
visible
=
false
;
fish
[
'
child_paopao_ani
'
].
ref
.
visible
=
true
;
fish
[
'
child_paopao_ani
'
].
ref
.
visible
=
true
;
// 注销该鱼的点击事件
this
.
unsubscribeFishEvent
(
fish
.
fishId
);
// 创建飞向水桶的小鱼动画
// 创建飞向水桶的小鱼动画
this
.
createFlyingFish
(
fish
);
this
.
createFlyingFish
(
fish
);
this
.
brokePaopaoAni
(
fish
);
this
.
brokePaopaoAni
(
fish
);
...
@@ -1757,6 +1761,17 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -1757,6 +1761,17 @@ export class PlayComponent implements OnInit, OnDestroy {
this
.
updateFish
();
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 {
...
@@ -1765,6 +1780,8 @@ export class PlayComponent implements OnInit, OnDestroy {
// 从渲染对象数组中移除所有鱼
// 从渲染对象数组中移除所有鱼
for
(
let
i
=
this
.
m_fishArray
.
length
-
1
;
i
>=
0
;
i
--
)
{
for
(
let
i
=
this
.
m_fishArray
.
length
-
1
;
i
>=
0
;
i
--
)
{
const
fish
=
this
.
m_fishArray
[
i
];
const
fish
=
this
.
m_fishArray
[
i
];
// 注销该鱼的点击事件
this
.
unsubscribeFishEvent
(
fish
.
fishId
);
// 从渲染对象数组中移除
// 从渲染对象数组中移除
this
.
m_renderObject
=
this
.
m_renderObject
.
filter
(
item
=>
item
.
element
!==
fish
.
ref
);
this
.
m_renderObject
=
this
.
m_renderObject
.
filter
(
item
=>
item
.
element
!==
fish
.
ref
);
}
}
...
@@ -1838,6 +1855,8 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -1838,6 +1855,8 @@ export class PlayComponent implements OnInit, OnDestroy {
// 如果鱼游出了屏幕左侧,从数组中移除
// 如果鱼游出了屏幕左侧,从数组中移除
if
(
fish
.
ref
.
x
<
-
fish
.
ref
.
width
*
fish
.
ref
.
scaleX
/
2
)
{
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
);
this
.
m_renderObject
=
this
.
m_renderObject
.
filter
(
item
=>
item
.
element
!==
fish
.
ref
);
// 重新构建渲染数组
// 重新构建渲染数组
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment