Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
Cocos-1010
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
等吃饭
Cocos-1010
Commits
172bc42b
Commit
172bc42b
authored
May 22, 2023
by
Friends233
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
拖拽填入方块
parent
3086c8db
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
165 additions
and
234 deletions
+165
-234
Game.fire
assets/Scenes/Game.fire
+141
-186
block.ts
assets/Script/block.ts
+12
-14
miniBlock.ts
assets/Script/miniBlock.ts
+11
-20
block.prefab
assets/resources/prefab/block.prefab
+1
-14
No files found.
assets/Scenes/Game.fire
View file @
172bc42b
This diff is collapsed.
Click to expand it.
assets/Script/block.ts
View file @
172bc42b
...
...
@@ -31,13 +31,12 @@ export default class Block extends cc.Component {
/** 放置block */
setBlockMatrix
()
{
const
targetNodeWorldPos
=
this
.
node
.
parent
.
convertToWorldSpaceAR
(
this
.
node
.
getPosition
())
const
matrix
=
cc
.
find
(
'blockMatrix'
,
this
.
node
.
parent
.
parent
)
const
pos
=
this
.
node
.
convertToWorldSpaceAR
(
this
.
node
.
getPosition
())
const
{
targetPos
,
targetNode
}
=
this
.
posFindBlock
(
pos
)
const
{
targetPos
,
targetNode
}
=
this
.
posFindBlock
(
targetNodeWorldPos
)
this
.
isMove
=
false
const
p
=
targetNode
.
convertToNodeSpaceAR
(
cc
.
v2
(
targetPos
.
x
,
targetPos
.
y
))
console
.
log
(
'set'
,
p
.
x
,
p
.
y
)
this
.
node
.
setPosition
(
p
)
const
p
=
this
.
node
.
convertToNodeSpaceAR
(
targetPos
)
this
.
node
.
setPosition
(
cc
.
v2
(
p
.
x
+
this
.
node
.
x
,
p
.
y
+
this
.
node
.
y
))
}
/**
...
...
@@ -46,22 +45,21 @@ export default class Block extends cc.Component {
*/
posFindBlock
(
pos
:
cc
.
Vec2
)
{
const
matrix
=
cc
.
find
(
'blockMatrix'
,
this
.
node
.
parent
.
parent
)
const
matrixPos
=
matrix
.
children
.
map
((
node
)
=>
{
const
nodePos
=
node
.
convertToWorldSpaceAR
(
node
.
getPosition
())
return
{
x
:
nodePos
.
x
,
y
:
nodePos
.
y
+
300
}
})
let
minX
=
999999
,
minIdx
=
-
1
matrixPos
.
forEach
((
nodePos
:
cc
.
Vec2
,
i
)
=>
{
const
matrixPos
=
matrix
.
children
.
map
((
node
,
i
)
=>
{
const
nodePos
=
matrix
.
convertToWorldSpaceAR
(
node
.
getPosition
())
// 两点间的距离
const
offsetX
=
Math
.
sqrt
(
Math
.
pow
((
nodePos
.
x
-
pos
.
x
),
2
)
+
Math
.
pow
((
nodePos
.
y
-
pos
.
y
),
2
))
if
(
offsetX
<
minX
)
{
minX
=
offsetX
minIdx
=
i
}
return
{
nodePos
,
node
}
})
return
{
targetPos
:
matrixPos
[
minIdx
]
,
targetNode
:
matrix
.
children
[
minIdx
]
}
return
{
targetPos
:
matrixPos
[
minIdx
]
.
nodePos
,
targetNode
:
matrixPos
[
minIdx
].
node
}
}
addNodeEvent
()
{
...
...
assets/Script/miniBlock.ts
View file @
172bc42b
...
...
@@ -19,47 +19,38 @@ export default class NewClass extends cc.Component {
/** 方块矩阵外层容器 */
blockMatrix
:
cc
.
Node
=
null
/** 外层容器 */
stage
:
cc
.
Canvas
=
null
start
()
{
this
.
viewHeight
=
cc
.
view
.
getVisibleSize
().
height
this
.
viewWidth
=
cc
.
view
.
getVisibleSize
().
width
this
.
blockMatrix
=
cc
.
find
(
'blockMatrix'
,
this
.
node
.
parent
)
this
.
stage
=
this
.
node
.
parent
this
.
addNodeEvent
()
const
matrix
=
this
.
blockMatrix
=
cc
.
find
(
'blockMatrix'
,
this
.
node
.
parent
)
const
node
=
matrix
.
children
[
0
]
const
k
=
node
.
convertToWorldSpaceAR
(
node
.
getPosition
())
console
.
log
(
'start'
,
k
.
x
,
k
.
y
)
}
setBlockMatrixAll
(
parentPos
:
cc
.
Vec2
)
{
setBlockMatrixAll
()
{
this
.
isMove
=
false
const
allBlock
=
this
.
node
.
children
allBlock
.
forEach
((
node
:
cc
.
Node
)
=>
{
const
scripts
=
node
.
getComponent
(
'block'
)
scripts
.
setBlockMatrix
()
})
const
node
=
allBlock
[
0
]
const
scripts
=
node
.
getComponent
(
'block'
)
// scripts.setBlockMatrix()
}
addNodeEvent
()
{
this
.
node
.
on
(
cc
.
Node
.
EventType
.
TOUCH_START
,
()
=>
{
console
.
log
(
'TOUCH_START'
)
this
.
isMove
=
true
this
.
node
.
scale
=
1.
5
7
this
.
node
.
scale
=
1.7
},
this
)
this
.
node
.
on
(
cc
.
Node
.
EventType
.
TOUCH_END
,
()
=>
{
console
.
log
(
'TOUCH_END'
)
this
.
setBlockMatrixAll
(
this
.
node
.
getPosition
())
this
.
setBlockMatrixAll
()
},
this
)
this
.
node
.
on
(
cc
.
Node
.
EventType
.
TOUCH_MOVE
,
(
e
:
cc
.
Event
.
EventTouch
)
=>
{
const
allBlock
=
this
.
node
.
children
const
matrix
=
this
.
blockMatrix
const
node
=
allBlock
[
0
]
const
blockPos
=
node
.
convertToWorldSpaceAR
(
node
.
getPosition
())
console
.
log
(
blockPos
.
x
,
blockPos
.
y
);
console
.
log
(
"========================"
)
if
(
this
.
isMove
)
{
const
pos
:
cc
.
Vec2
=
e
.
getPreviousLocation
()
...
...
assets/resources/prefab/block.prefab
View file @
172bc42b
...
...
@@ -21,13 +21,10 @@
"_components": [
{
"__id__": 2
},
{
"__id__": 3
}
],
"_prefab": {
"__id__":
4
"__id__":
3
},
"_opacity": 255,
"_color": {
...
...
@@ -108,16 +105,6 @@
"_atlas": null,
"_id": ""
},
{
"__type__": "b1207cbMWhNVLKTFVfAq/t2",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
...
...
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