Commit 172bc42b authored by Friends233's avatar Friends233

拖拽填入方块

parent 3086c8db
......@@ -108,19 +108,19 @@
"__id__": 35
},
{
"__id__": 47
"__id__": 49
}
],
"_active": true,
"_components": [
{
"__id__": 84
"__id__": 86
},
{
"__id__": 85
"__id__": 87
},
{
"__id__": 86
"__id__": 88
}
],
"_prefab": null,
......@@ -1675,22 +1675,19 @@
"__id__": 36
},
{
"__id__": 38
},
{
"__id__": 40
"__id__": 39
},
{
"__id__": 42
},
{
"__id__": 44
"__id__": 45
}
],
"_active": true,
"_components": [
{
"__id__": 46
"__id__": 48
}
],
"_prefab": null,
......@@ -1753,6 +1750,9 @@
"_components": [
{
"__id__": 37
},
{
"__id__": 38
}
],
"_prefab": null,
......@@ -1778,7 +1778,7 @@
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
-70.25,
-73.25,
70.25,
0,
0,
......@@ -1835,6 +1835,16 @@
"_atlas": null,
"_id": "490UXZAcVFBolH9bTdJw6r"
},
{
"__type__": "b1207cbMWhNVLKTFVfAq/t2",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 36
},
"_enabled": true,
"_id": "a4SYzpDRhLKbA1M1ndEoSa"
},
{
"__type__": "cc.Node",
"_name": "mb",
......@@ -1846,7 +1856,10 @@
"_active": true,
"_components": [
{
"__id__": 39
"__id__": 40
},
{
"__id__": 41
}
],
"_prefab": null,
......@@ -1872,7 +1885,7 @@
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
-35.25,
-38.25,
70.25,
0,
0,
......@@ -1902,7 +1915,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 38
"__id__": 39
},
"_enabled": true,
"_materials": [
......@@ -1930,98 +1943,14 @@
"_id": "e8X+I+Kf9MMKUii9R4Og6A"
},
{
"__type__": "cc.Node",
"_name": "mb",
"_objFlags": 0,
"_parent": {
"__id__": 35
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 41
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 88,
"g": 217,
"b": 179,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 33.5,
"height": 33.5
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
-0.25,
70.25,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "de4VG5iUVECaTecGJl6/WV"
},
{
"__type__": "cc.Sprite",
"__type__": "b1207cbMWhNVLKTFVfAq/t2",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 40
"__id__": 39
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_spriteFrame": {
"__uuid__": "a23235d1-15db-4b95-8439-a2e005bfff91"
},
"_type": 0,
"_sizeMode": 0,
"_fillType": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_atlas": null,
"_id": "daTgS4oI9I+oq/JcYZ04DA"
"_id": "63a0+R6PtPZJEYz5VGpUZF"
},
{
"__type__": "cc.Node",
......@@ -2035,6 +1964,9 @@
"_components": [
{
"__id__": 43
},
{
"__id__": 44
}
],
"_prefab": null,
......@@ -2060,7 +1992,7 @@
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
34.75,
-3.25,
70.25,
0,
0,
......@@ -2083,7 +2015,7 @@
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "44un+rmqtJfLnmInb/6pm8"
"_id": "fer+aCFxRKwYdaDkI1rASj"
},
{
"__type__": "cc.Sprite",
......@@ -2115,7 +2047,17 @@
"_fillRange": 0,
"_isTrimmedMode": true,
"_atlas": null,
"_id": "5eXZz877tEWIoN8jw9ypNc"
"_id": "b5W6ztml5OUpbHXPnGIfOX"
},
{
"__type__": "b1207cbMWhNVLKTFVfAq/t2",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 42
},
"_enabled": true,
"_id": "4ecYOoNDZMP5mT5LqBUEhP"
},
{
"__type__": "cc.Node",
......@@ -2128,7 +2070,10 @@
"_active": true,
"_components": [
{
"__id__": 45
"__id__": 46
},
{
"__id__": 47
}
],
"_prefab": null,
......@@ -2154,7 +2099,7 @@
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
69.75,
31.75,
70.25,
0,
0,
......@@ -2177,14 +2122,14 @@
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "35XTtnZ9tMA4KldFtMw/vl"
"_id": "aftefayNFOAbIxQX3uji4/"
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 44
"__id__": 45
},
"_enabled": true,
"_materials": [
......@@ -2209,7 +2154,17 @@
"_fillRange": 0,
"_isTrimmedMode": true,
"_atlas": null,
"_id": "33mc8cfdVHUIV4w/oyQdVD"
"_id": "17l0+bYu9HRY1HFZdGmn3O"
},
{
"__type__": "b1207cbMWhNVLKTFVfAq/t2",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 45
},
"_enabled": true,
"_id": "015qvGmjFBvZ4YMP/Y7Qz3"
},
{
"__type__": "005cbl0Ta1Fzqy4+w8dpg0o",
......@@ -2230,25 +2185,25 @@
},
"_children": [
{
"__id__": 48
"__id__": 50
},
{
"__id__": 55
"__id__": 57
},
{
"__id__": 62
"__id__": 64
},
{
"__id__": 69
"__id__": 71
},
{
"__id__": 76
"__id__": 78
}
],
"_active": true,
"_components": [
{
"__id__": 83
"__id__": 85
}
],
"_prefab": null,
......@@ -2304,17 +2259,17 @@
"_name": "next",
"_objFlags": 0,
"_parent": {
"__id__": 47
"__id__": 49
},
"_children": [
{
"__id__": 49
"__id__": 51
}
],
"_active": true,
"_components": [
{
"__id__": 54
"__id__": 56
}
],
"_prefab": null,
......@@ -2370,20 +2325,20 @@
"_name": "Background",
"_objFlags": 512,
"_parent": {
"__id__": 48
"__id__": 50
},
"_children": [
{
"__id__": 50
"__id__": 52
}
],
"_active": true,
"_components": [
{
"__id__": 52
"__id__": 54
},
{
"__id__": 53
"__id__": 55
}
],
"_prefab": null,
......@@ -2439,13 +2394,13 @@
"_name": "Label",
"_objFlags": 512,
"_parent": {
"__id__": 49
"__id__": 51
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 51
"__id__": 53
}
],
"_prefab": null,
......@@ -2501,7 +2456,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 50
"__id__": 52
},
"_enabled": true,
"_materials": [
......@@ -2534,7 +2489,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 49
"__id__": 51
},
"_enabled": true,
"_materials": [
......@@ -2566,7 +2521,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 49
"__id__": 51
},
"_enabled": true,
"alignMode": 0,
......@@ -2593,7 +2548,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 48
"__id__": 50
},
"_enabled": true,
"_normalMaterial": null,
......@@ -2666,7 +2621,7 @@
"__uuid__": "29158224-f8dd-4661-a796-1ffab537140e"
},
"_N$target": {
"__id__": 49
"__id__": 51
},
"_id": "dfguRopclGIqZktevHrnhT"
},
......@@ -2675,17 +2630,17 @@
"_name": "refreshProp",
"_objFlags": 0,
"_parent": {
"__id__": 47
"__id__": 49
},
"_children": [
{
"__id__": 56
"__id__": 58
}
],
"_active": true,
"_components": [
{
"__id__": 61
"__id__": 63
}
],
"_prefab": null,
......@@ -2741,20 +2696,20 @@
"_name": "Background",
"_objFlags": 512,
"_parent": {
"__id__": 55
"__id__": 57
},
"_children": [
{
"__id__": 57
"__id__": 59
}
],
"_active": true,
"_components": [
{
"__id__": 59
"__id__": 61
},
{
"__id__": 60
"__id__": 62
}
],
"_prefab": null,
......@@ -2810,13 +2765,13 @@
"_name": "Label",
"_objFlags": 512,
"_parent": {
"__id__": 56
"__id__": 58
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 58
"__id__": 60
}
],
"_prefab": null,
......@@ -2872,7 +2827,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 57
"__id__": 59
},
"_enabled": true,
"_materials": [
......@@ -2905,7 +2860,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 56
"__id__": 58
},
"_enabled": true,
"_materials": [
......@@ -2937,7 +2892,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 56
"__id__": 58
},
"_enabled": true,
"alignMode": 0,
......@@ -2964,7 +2919,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 55
"__id__": 57
},
"_enabled": true,
"_normalMaterial": null,
......@@ -3037,7 +2992,7 @@
"__uuid__": "29158224-f8dd-4661-a796-1ffab537140e"
},
"_N$target": {
"__id__": 56
"__id__": 58
},
"_id": "06Xai9BG1CKLT3kEY+FESD"
},
......@@ -3046,17 +3001,17 @@
"_name": "addSpeed",
"_objFlags": 0,
"_parent": {
"__id__": 47
"__id__": 49
},
"_children": [
{
"__id__": 63
"__id__": 65
}
],
"_active": true,
"_components": [
{
"__id__": 68
"__id__": 70
}
],
"_prefab": null,
......@@ -3112,20 +3067,20 @@
"_name": "Background",
"_objFlags": 512,
"_parent": {
"__id__": 62
"__id__": 64
},
"_children": [
{
"__id__": 64
"__id__": 66
}
],
"_active": true,
"_components": [
{
"__id__": 66
"__id__": 68
},
{
"__id__": 67
"__id__": 69
}
],
"_prefab": null,
......@@ -3181,13 +3136,13 @@
"_name": "Label",
"_objFlags": 512,
"_parent": {
"__id__": 63
"__id__": 65
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 65
"__id__": 67
}
],
"_prefab": null,
......@@ -3243,7 +3198,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 64
"__id__": 66
},
"_enabled": true,
"_materials": [
......@@ -3276,7 +3231,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 63
"__id__": 65
},
"_enabled": true,
"_materials": [
......@@ -3308,7 +3263,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 63
"__id__": 65
},
"_enabled": true,
"alignMode": 0,
......@@ -3335,7 +3290,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 62
"__id__": 64
},
"_enabled": true,
"_normalMaterial": null,
......@@ -3408,7 +3363,7 @@
"__uuid__": "29158224-f8dd-4661-a796-1ffab537140e"
},
"_N$target": {
"__id__": 63
"__id__": 65
},
"_id": "17ggxhM1pE6Lku10v0bXyS"
},
......@@ -3417,17 +3372,17 @@
"_name": "init",
"_objFlags": 0,
"_parent": {
"__id__": 47
"__id__": 49
},
"_children": [
{
"__id__": 70
"__id__": 72
}
],
"_active": true,
"_components": [
{
"__id__": 75
"__id__": 77
}
],
"_prefab": null,
......@@ -3483,20 +3438,20 @@
"_name": "Background",
"_objFlags": 512,
"_parent": {
"__id__": 69
"__id__": 71
},
"_children": [
{
"__id__": 71
"__id__": 73
}
],
"_active": true,
"_components": [
{
"__id__": 73
"__id__": 75
},
{
"__id__": 74
"__id__": 76
}
],
"_prefab": null,
......@@ -3552,13 +3507,13 @@
"_name": "Label",
"_objFlags": 512,
"_parent": {
"__id__": 70
"__id__": 72
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 72
"__id__": 74
}
],
"_prefab": null,
......@@ -3614,7 +3569,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 71
"__id__": 73
},
"_enabled": true,
"_materials": [
......@@ -3647,7 +3602,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 70
"__id__": 72
},
"_enabled": true,
"_materials": [
......@@ -3679,7 +3634,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 70
"__id__": 72
},
"_enabled": true,
"alignMode": 0,
......@@ -3706,7 +3661,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 69
"__id__": 71
},
"_enabled": true,
"_normalMaterial": null,
......@@ -3779,7 +3734,7 @@
"__uuid__": "29158224-f8dd-4661-a796-1ffab537140e"
},
"_N$target": {
"__id__": 70
"__id__": 72
},
"_id": "57bHTVH8ZOjZpjTzCUb0mD"
},
......@@ -3788,17 +3743,17 @@
"_name": "start",
"_objFlags": 0,
"_parent": {
"__id__": 47
"__id__": 49
},
"_children": [
{
"__id__": 77
"__id__": 79
}
],
"_active": true,
"_components": [
{
"__id__": 82
"__id__": 84
}
],
"_prefab": null,
......@@ -3854,20 +3809,20 @@
"_name": "Background",
"_objFlags": 512,
"_parent": {
"__id__": 76
"__id__": 78
},
"_children": [
{
"__id__": 78
"__id__": 80
}
],
"_active": true,
"_components": [
{
"__id__": 80
"__id__": 82
},
{
"__id__": 81
"__id__": 83
}
],
"_prefab": null,
......@@ -3923,13 +3878,13 @@
"_name": "Label",
"_objFlags": 512,
"_parent": {
"__id__": 77
"__id__": 79
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 79
"__id__": 81
}
],
"_prefab": null,
......@@ -3985,7 +3940,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 78
"__id__": 80
},
"_enabled": true,
"_materials": [
......@@ -4018,7 +3973,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 77
"__id__": 79
},
"_enabled": true,
"_materials": [
......@@ -4050,7 +4005,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 77
"__id__": 79
},
"_enabled": true,
"alignMode": 0,
......@@ -4077,7 +4032,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 76
"__id__": 78
},
"_enabled": true,
"_normalMaterial": null,
......@@ -4150,7 +4105,7 @@
"__uuid__": "29158224-f8dd-4661-a796-1ffab537140e"
},
"_N$target": {
"__id__": 77
"__id__": 79
},
"_id": "6cOXQVh5BCV4WKrcZc4zUt"
},
......@@ -4159,7 +4114,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 47
"__id__": 49
},
"_enabled": true,
"_layoutSize": {
......
......@@ -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() {
......
......@@ -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.57
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()
......
......@@ -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": {
......
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