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
b0f51c7b
Commit
b0f51c7b
authored
Jun 16, 2023
by
Tt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
9ac395b3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
140 additions
and
33 deletions
+140
-33
hy01_danci.fire
assets/hy01_danci/scene/hy01_danci.fire
+14
-14
hy01_danci.ts
assets/hy01_danci/scene/hy01_danci.ts
+124
-19
creator.d.ts
creator.d.ts
+2
-0
No files found.
assets/hy01_danci/scene/hy01_danci.fire
View file @
b0f51c7b
...
...
@@ -577,8 +577,8 @@
},
"_contentSize": {
"__type__": "cc.Size",
"width":
52
,
"height":
40
0
"width":
1920
,
"height":
108
0
},
"_anchorPoint": {
"__type__": "cc.Vec2",
...
...
@@ -590,7 +590,7 @@
"ctor": "Float64Array",
"array": [
0,
6
0,
0,
0,
0,
0,
...
...
@@ -624,10 +624,10 @@
"_enabled": true,
"_layoutSize": {
"__type__": "cc.Size",
"width":
52
,
"height":
40
0
"width":
1920
,
"height":
108
0
},
"_resize":
1
,
"_resize":
0
,
"_N$layoutType": 1,
"_N$cellSize": {
"__type__": "cc.Size",
...
...
@@ -774,7 +774,7 @@
"__id__": 10
},
"_children": [],
"_active":
fals
e,
"_active":
tru
e,
"_components": [
{
"__id__": 16
...
...
@@ -797,20 +797,20 @@
},
"_contentSize": {
"__type__": "cc.Size",
"width":
10
0,
"width": 0,
"height": 300
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0
.5
,
"x": 0,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0
,
0
,
-532.511
,
-304.761
,
0,
0,
0,
...
...
@@ -841,7 +841,7 @@
"node": {
"__id__": 15
},
"_enabled":
tru
e,
"_enabled":
fals
e,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
...
...
@@ -946,7 +946,7 @@
"_enabled": true,
"_layoutSize": {
"__type__": "cc.Size",
"width":
10
0,
"width": 0,
"height": 300
},
"_resize": 1,
...
...
@@ -961,7 +961,7 @@
"_N$paddingRight": 0,
"_N$paddingTop": 0,
"_N$paddingBottom": 0,
"_N$spacingX":
6
0,
"_N$spacingX":
4
0,
"_N$spacingY": 0,
"_N$verticalDirection": 1,
"_N$horizontalDirection": 0,
...
...
assets/hy01_danci/scene/hy01_danci.ts
View file @
b0f51c7b
...
...
@@ -145,29 +145,44 @@ export default class SceneComponent extends MyCocosSceneComponent {
pg
.
view
.
removChildren
(
this
.
answer_word
)
let
curWord
=
this
.
word_list
[
this
.
cur_index
];
let
ansArr
=
curWord
[
'
answer
'
];
// 大写的正则
const
reg
=
/^
[
A-Z
]
+$/
;
let
strArr
=
curWord
[
'
word
'
].
split
(
''
);
if
(
!
strArr
)
{
console
.
log
(
"
error->curWord
"
)
return
;
}
strArr
.
forEach
(
str
=>
{
const
lower
=
str
.
toLowerCase
()
let
prefabNode
:
cc
.
Node
;
if
(
reg
.
test
(
str
))
{
// 为大写
prefabNode
=
pg
.
view
.
find
(
this
.
upper_shadow
,
`
${
lower
}
2_di`
)
ansArr
.
forEach
((
ans
,
i
)
=>
{
// // 为大写
// let child = this.getWordBgNodeByStr(str);
// child.data = {
// group: i
// };
// //为小写
// pg.view.addChild(this.word_area, child)
if
(
ans
.
length
>
1
)
{
// 长度大于一需要做拆分
let
ansStrArr
=
ans
.
split
(
''
);
ansStrArr
.
forEach
((
str
,
m
)
=>
{
let
child
=
this
.
getWordBgNodeByStr
(
str
);
child
.
data
=
{
group
:
i
,
index
:
m
}
pg
.
view
.
addChild
(
this
.
word_area
,
child
)
})
}
else
{
prefabNode
=
pg
.
view
.
find
(
this
.
lower_shadow
,
`
${
lower
}
_di`
)
let
child
=
this
.
getWordBgNodeByStr
(
ans
);
child
.
data
=
{
group
:
i
,
index
:
0
}
pg
.
view
.
addChild
(
this
.
word_area
,
child
)
}
let
child
=
pg
.
view
.
clone
(
prefabNode
)
child
.
active
=
true
//为小写
pg
.
view
.
addChild
(
this
.
word_area
,
child
)
});
let
ansArr
=
curWord
[
'
answer
'
];
if
(
!
ansArr
.
length
)
{
console
.
log
(
"
error->curWord
"
)
return
;
...
...
@@ -180,6 +195,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
let
pos
=
this
.
getItemPosByAns
(
ansArr
,
ans
);
itemClone
.
x
=
pos
.
x
;
itemClone
.
y
=
pos
.
y
;
itemClone
.
orgPos
=
cc
.
v2
(
pos
);
itemClone
.
active
=
true
;
pg
.
view
.
addChild
(
this
.
answer_word
,
itemClone
);
itemClone
.
on
(
cc
.
Node
.
EventType
.
TOUCH_START
,
this
.
onTouchStart
,
this
);
...
...
@@ -189,22 +205,38 @@ export default class SceneComponent extends MyCocosSceneComponent {
if
(
ans
.
length
>
1
)
{
// 长度大于一需要做拆分
let
ansStrArr
=
ans
.
split
(
''
);
ansStrArr
.
forEach
((
str
)
=>
{
ansStrArr
.
forEach
((
str
,
m
)
=>
{
let
child
=
this
.
getWordNodeByStr
(
str
);
child
.
data
=
{
group
:
i
,
index
:
m
}
pg
.
view
.
addChild
(
itemClone
,
child
)
})
}
else
{
let
child
=
this
.
getWordNodeByStr
(
ans
);
child
.
data
=
{
group
:
i
,
index
:
0
}
pg
.
view
.
addChild
(
itemClone
,
child
)
}
});
}
getItemPosByAns
(
ansArr
,
ans
)
{
let
pos
=
cc
.
v2
(
0
,
0
)
let
i
=
ansArr
.
indexOf
(
ans
);
let
width
=
260
*
ans
.
length
pos
.
x
=
i
*
260
-
width
/
2
;
pos
.
y
=
-
200
;
let
count
=
ansArr
.
indexOf
(
ans
);
let
i
=
0
;
ansArr
.
forEach
((
ar
,
m
)
=>
{
if
(
m
<
count
)
{
i
+=
ar
.
length
}
})
let
orgX
=
-
520
;
pos
.
x
=
orgX
+
i
*
210
;
pos
.
y
=
-
300
;
return
pos
;
}
...
...
@@ -218,7 +250,35 @@ export default class SceneComponent extends MyCocosSceneComponent {
child
.
active
=
true
;
return
child
;
}
getWordBgNodeByStr
(
str
)
{
const
reg
=
/^
[
A-Z
]
+$/
;
const
lower
=
str
.
toLowerCase
()
let
prefabNode
=
reg
.
test
(
str
)
?
pg
.
view
.
find
(
this
.
upper_shadow
,
`
${
lower
}
2_di`
)
:
pg
.
view
.
find
(
this
.
lower_shadow
,
`
${
lower
}
_di`
);
let
child
=
pg
.
view
.
clone
(
prefabNode
)
child
.
active
=
true
child
.
x
=
0
;
child
.
y
=
0
;
return
child
;
}
collider
(
node
)
{
// 每个字母
// let worldPos = this.word_area.convertToNodeSpaceAR(node.convertToWorldSpaceAR(cc.v2(0, 0)))
let
worldPos
=
cc
.
v2
(
node
.
x
+
node
.
width
/
2
,
node
.
y
);
let
colliderNode
=
null
;
this
.
word_area
.
children
.
forEach
(
word
=>
{
// let center = word.parent.convertToNodeSpaceAR(word.convertToWorldSpaceAR(cc.v2(0, 0)))
let
center
=
cc
.
v2
(
word
);
let
maxX
=
center
.
x
+
word
.
width
/
2
;
let
minX
=
center
.
x
-
word
.
width
/
2
;
let
maxY
=
center
.
y
+
word
.
width
/
2
;
let
minY
=
center
.
y
-
word
.
width
/
2
;
if
(
worldPos
.
x
<
maxX
&&
worldPos
.
x
>
minX
&&
worldPos
.
y
<
maxY
&&
worldPos
.
y
>
minY
)
{
colliderNode
=
word
;
}
})
return
colliderNode
;
}
onTouchStart
(
event
)
{
console
.
log
(
'
1
'
)
}
...
...
@@ -230,7 +290,41 @@ export default class SceneComponent extends MyCocosSceneComponent {
node
.
y
+=
delta
.
y
;
}
onTouchEnd
(
event
)
{
let
node
=
event
.
target
;
// 跟字母区域进行碰撞检测
let
colliderNode
=
this
.
collider
(
node
);
// 获取当前待碰撞区域
if
(
!
colliderNode
)
{
node
.
x
=
node
.
orgPos
.
x
node
.
y
=
node
.
orgPos
.
y
}
else
{
let
data
=
colliderNode
.
data
;
console
.
log
(
JSON
.
stringify
(
data
));
// 找到目标坐标
// let groupNode = this.word_area.children.find(node => {
// return node.data.group == data.group && node.data.index == 0;
// })
// let pos1 = cc.v2(groupNode.x - groupNode.width / 2);
// cc.tween(node).to(0.3, { x: pos1.x, y: pos1.y, scale: 1 }).start();
// nd运动到对应的节点
let
list
=
[]
node
.
children
.
forEach
(
nd
=>
{
nd
.
parent
=
node
.
parent
;
})
// let target = this.getBgNodeByGroupIndex(nd.data.group, nd.data.index);
// let pos = node.convertToNodeSpaceAR(target.convertToWorldSpaceAR(cc.v2(0, 0)));
// cc.tween(nd).to(0.3, { x: pos.x, y: pos.y, scale: 0.8 }).start();
node
.
off
(
cc
.
Node
.
EventType
.
TOUCH_START
,
this
.
onTouchStart
,
this
);
node
.
off
(
cc
.
Node
.
EventType
.
TOUCH_MOVE
,
this
.
onTouchMove
,
this
);
node
.
off
(
cc
.
Node
.
EventType
.
TOUCH_END
,
this
.
onTouchEnd
,
this
);
}
}
getBgNodeByGroupIndex
(
group
,
index
)
{
let
groupNode
=
this
.
word_area
.
children
.
find
(
node
=>
{
return
node
.
data
.
group
==
group
&&
node
.
data
.
index
==
index
;
})
return
groupNode
;
}
private
count
:
number
;
...
...
@@ -258,4 +352,15 @@ export default class SceneComponent extends MyCocosSceneComponent {
})
}
}
// 重构方案
// 1.所有坐标均为计算得到不适用group
// 2.关联内容,在touch的时候同步运动
// 3.图片的点击区域,需要套在一个item里面,item的宽度是固定的,用于处理间隔问题。
// 4.在同一坐标系下,所有的节点均可以直接运动到指定的位置。
// 方案2
// 目前方案不变。
// 增加补丁
// 1.显示字母手动计算 零散的分布
// 2.touchmove的时候获取关联字母
// 3.关联字母跟随目前的touch走。
creator.d.ts
View file @
b0f51c7b
...
...
@@ -4588,6 +4588,8 @@ declare namespace cc {
/** !#en Returns a normalized vector representing the forward direction (Z axis) of the node in world space.
!#zh 获取节点正前方(z 轴)面对的方向,返回值为世界坐标系下的归一化向量 */
forward
:
Vec3
;
orgPos
:
Vec2
;
data
:
any
;
/**
@param name name
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