Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hy04_pinci
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
hy04_pinci
Commits
16f2c8f5
Commit
16f2c8f5
authored
Jun 16, 2023
by
Tt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
项目完成
parent
7e914c05
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
21 deletions
+67
-21
hy01_danci.fire
assets/hy01_danci/scene/hy01_danci.fire
+1
-1
hy01_danci.ts
assets/hy01_danci/scene/hy01_danci.ts
+66
-20
No files found.
assets/hy01_danci/scene/hy01_danci.fire
View file @
16f2c8f5
...
...
@@ -802,7 +802,7 @@
"node": {
"__id__": 14
},
"_enabled":
fals
e,
"_enabled":
tru
e,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
...
...
assets/hy01_danci/scene/hy01_danci.ts
View file @
16f2c8f5
...
...
@@ -3,7 +3,10 @@ import { MyCocosSceneComponent } from "../script/MyCocosSceneComponent_hy01_danc
import
pg
from
"
./pg_hy01_danci
"
;
const
{
ccclass
,
property
}
=
cc
.
_decorator
;
enum
WORD_TYPE
{
TOUCH
,
LINE
}
@
ccclass
export
default
class
SceneComponent
extends
MyCocosSceneComponent
{
addPreloadImage
()
{
...
...
@@ -180,7 +183,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
let
child
=
this
.
getWordBgNodeByStr
(
str
);
child
.
data
=
{
count
:
count
,
group
:
i
,
index
:
m
}
this
.
successGroupIds
[
`
${
i
}
`
]
=
false
;
let
pos
=
this
.
getWordBgPosByAns
(
ansArr
,
child
.
data
)
let
pos
=
this
.
getWordBgPosByAns
(
ansArr
,
[
str
],
child
.
data
)
child
.
x
=
pos
.
x
;
child
.
y
=
pos
.
y
;
this
.
wordBgList
.
push
(
child
);
...
...
@@ -214,7 +217,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
count
++
;
let
child
=
this
.
getWordNodeByStr
(
str
);
child
.
data
=
{
group
:
i
,
index
:
m
,
count
:
count
};
let
pos
=
this
.
getWordPosByAns
(
ansArr
,
child
.
data
);
let
pos
=
this
.
getWordPosByAns
(
ansArr
,
[
str
],
child
.
data
);
child
.
x
=
pos
.
x
;
child
.
y
=
pos
.
y
;
this
.
wordList
.
push
(
child
)
...
...
@@ -230,50 +233,93 @@ export default class SceneComponent extends MyCocosSceneComponent {
getItemPosWidthByAns
(
ansArr
,
itemAnsArr
,
count
)
{
//根据总长度计算出需要预留的空间大小
let
defaultPos
=
cc
.
v2
(
0
,
-
300
);
let
singleWordWidth
=
220
;
let
orgPos
=
this
.
getTotalWordWidth
(
ansArr
,
singleWordWidth
,
defaultPos
);
let
itemWidth
=
itemAnsArr
.
length
*
singleWordWidth
;
let
orgPos
=
this
.
getTotalWordOrgPos
(
WORD_TYPE
.
TOUCH
,
ansArr
,
defaultPos
)
;
let
itemWidth
=
this
.
getItemWordWidth
(
WORD_TYPE
.
TOUCH
,
itemAnsArr
);
let
leftWidth
=
this
.
getLeftWidthByCount
(
WORD_TYPE
.
TOUCH
,
ansArr
,
count
)
;
// 计算当前是第几个
let
pos
=
cc
.
v2
(
0
,
0
);
pos
.
x
=
orgPos
.
x
+
count
*
singleWordWidth
;
pos
.
x
=
orgPos
.
x
+
leftWidth
+
itemWidth
/
2
;
pos
.
y
=
orgPos
.
y
;
if
(
itemAnsArr
.
length
>
0
)
{
pos
.
x
+=
itemWidth
/
2
-
singleWordWidth
/
2
;
//
pos.x += itemWidth / 2 - singleWordWidth / 2;
}
return
{
pos
:
pos
,
width
:
itemWidth
};
}
getWordPosByAns
(
ansArr
,
data
)
{
getWordPosByAns
(
ansArr
,
itemAnsArr
,
data
)
{
//根据总长度计算出需要预留的空间大小
let
defaultPos
=
cc
.
v2
(
0
,
-
300
);
let
singleWordWidth
=
220
;
let
orgPos
=
this
.
getTotalWordWidth
(
ansArr
,
singleWordWidth
,
defaultPos
);
// 计算当前是第几个
let
orgPos
=
this
.
getTotalWordOrgPos
(
WORD_TYPE
.
TOUCH
,
ansArr
,
defaultPos
);
let
itemWidth
=
this
.
getItemWordWidth
(
WORD_TYPE
.
TOUCH
,
itemAnsArr
);
let
count
=
data
.
count
;
let
leftWidth
=
this
.
getLeftWidthByCount
(
WORD_TYPE
.
TOUCH
,
ansArr
,
count
);
// 计算当前是第几个
let
pos
=
cc
.
v2
(
0
,
0
);
pos
.
x
=
orgPos
.
x
+
count
*
singleWordWidth
;
pos
.
x
=
orgPos
.
x
+
leftWidth
+
itemWidth
/
2
;
pos
.
y
=
orgPos
.
y
;
return
pos
;
}
getWordBgPosByAns
(
ansArr
,
data
)
{
getWordBgPosByAns
(
ansArr
,
itemAnsArr
,
data
)
{
//根据总长度计算出需要预留的空间大小
let
defaultPos
=
cc
.
v2
(
0
,
60
);
let
singleWordWidth
=
200
;
let
orgPos
=
this
.
getTotalWordWidth
(
ansArr
,
singleWordWidth
,
defaultPos
);
let
orgPos
=
this
.
getTotalWordOrgPos
(
WORD_TYPE
.
LINE
,
ansArr
,
defaultPos
)
;
let
itemWidth
=
this
.
getItemWordWidth
(
WORD_TYPE
.
LINE
,
itemAnsArr
);
// 计算当前是第几个
let
count
=
data
.
count
;
let
leftWidth
=
this
.
getLeftWidthByCount
(
WORD_TYPE
.
LINE
,
ansArr
,
count
);
let
pos
=
cc
.
v2
(
0
,
0
);
pos
.
x
=
orgPos
.
x
+
count
*
singleWordWidth
;
pos
.
x
=
orgPos
.
x
+
leftWidth
+
itemWidth
/
2
;
pos
.
y
=
orgPos
.
y
;
return
pos
;
}
getTotalWordWidth
(
ansArr
,
singleWordWidth
,
defaultPos
)
{
getTotalWordOrgPos
(
type
:
WORD_TYPE
,
ansArr
,
defaultPos
)
{
let
wordStr
=
ansArr
.
join
(
''
)
let
length
=
wordStr
.
length
;
let
totalWordWidth
=
length
*
singleWordWidth
;
let
totalWordWidth
=
0
;
wordStr
.
split
(
''
).
forEach
((
s
)
=>
{
let
w
=
this
.
getWordNodeWidth
(
type
,
s
);
totalWordWidth
+=
w
;
})
let
orgPos
=
cc
.
v2
(
-
totalWordWidth
/
2
+
defaultPos
.
x
,
defaultPos
.
y
);
return
orgPos
}
getItemWordWidth
(
type
:
WORD_TYPE
,
ansArr
)
{
let
wordStr
=
ansArr
.
join
(
''
)
let
totalWordWidth
=
0
;
wordStr
.
split
(
''
).
forEach
((
s
)
=>
{
let
w
=
this
.
getWordNodeWidth
(
type
,
s
);
totalWordWidth
+=
w
;
})
return
totalWordWidth
;
}
getLeftWidthByCount
(
type
:
WORD_TYPE
,
ansArr
,
count
)
{
let
wordStr
=
ansArr
.
join
(
''
)
let
totalWordWidth
=
0
;
wordStr
.
split
(
''
).
forEach
((
s
,
i
)
=>
{
let
w
=
this
.
getWordNodeWidth
(
type
,
s
);
if
(
i
>=
count
)
return
;
totalWordWidth
+=
w
;
})
return
totalWordWidth
;
}
getWordNodeWidth
(
type
,
str
)
{
const
reg
=
/^
[
A-Z
]
+$/
;
const
lower
=
str
.
toLowerCase
()
if
(
type
===
WORD_TYPE
.
TOUCH
)
{
let
prefabNode
=
reg
.
test
(
str
)
?
pg
.
view
.
find
(
this
.
upper_word
,
`
${
lower
}
2`
)
:
pg
.
view
.
find
(
this
.
lower_word
,
`
${
lower
}
`
)
return
prefabNode
.
width
+
20
;
}
else
{
let
prefabNode
=
reg
.
test
(
str
)
?
pg
.
view
.
find
(
this
.
upper_shadow
,
`
${
lower
}
2_di`
)
:
pg
.
view
.
find
(
this
.
lower_shadow
,
`
${
lower
}
_di`
);
return
prefabNode
.
width
+
30
;
}
}
getWordNodeByStr
(
str
)
{
const
reg
=
/^
[
A-Z
]
+$/
;
const
lower
=
str
.
toLowerCase
()
...
...
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