Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
comparetree
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
comparetree
Commits
7c2d2857
Commit
7c2d2857
authored
Jun 12, 2021
by
Tt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
基础玩法完成,再核对一次需求,然后开始调整动画
parent
6945f6fb
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
362 additions
and
216 deletions
+362
-216
scene.fire
play/assets/scene/scene/scene.fire
+289
-168
scene.js
play/assets/scene/scene/scene.js
+73
-48
No files found.
play/assets/scene/scene/scene.fire
View file @
7c2d2857
This diff is collapsed.
Click to expand it.
play/assets/scene/scene/scene.js
View file @
7c2d2857
...
...
@@ -137,55 +137,7 @@ cc.Class({
this
.
initSingleData
();
this
.
initAudio
();
this
.
initView
();
// this.initButton();
},
initButton
()
{
//触碰判断
let
item
=
pg
.
view
.
find
(
this
,
"
items/item
"
);
item
.
on
(
cc
.
Node
.
EventType
.
TOUCH_START
,
this
.
onStartItem
,
this
);
item
.
on
(
cc
.
Node
.
EventType
.
TOUCH_END
,
this
.
onEndItem
,
this
);
item
.
on
(
cc
.
Node
.
EventType
.
TOUCH_MOVE
,
this
.
onMoveItem
,
this
);
item
.
on
(
cc
.
Node
.
EventType
.
TOUCH_CANCEL
,
this
.
onCancelItem
,
this
);
},
onStartItem
(
touch
)
{
this
.
_startPos
=
cc
.
v2
(
touch
.
target
.
x
,
touch
.
target
.
y
);
let
touchPos
=
touch
.
getLocation
();
touch
.
target
.
x
=
touchPos
.
x
-
1280
/
2
;
touch
.
target
.
y
=
touchPos
.
y
-
720
/
2
;
},
onEndItem
(
touch
)
{
let
box_0
=
pg
.
view
.
find
(
this
,
"
box/box_0
"
);
//检测碰撞
if
(
this
.
checkCollider
(
touch
.
target
,
box_0
))
{
}
else
{
//碰撞失败退回原位置
touch
.
target
.
x
=
this
.
_startPos
.
x
;
touch
.
target
.
y
=
this
.
_startPos
.
y
;
}
},
onMoveItem
(
touch
)
{
//获取到的location是 当前点击的位置 而不是按钮原本应该所在的位置。
let
touchPos
=
touch
.
getLocation
();
touch
.
target
.
x
=
touchPos
.
x
-
1280
/
2
;
touch
.
target
.
y
=
touchPos
.
y
-
720
/
2
;
},
onCancelItem
(
touch
)
{
console
.
log
(
touch
);
},
checkCollider
(
item
,
box
)
{
return
item
.
x
>
box
.
x
-
box
.
width
/
2
&&
item
.
x
<
box
.
x
+
box
.
width
/
2
&&
item
.
y
>
box
.
y
-
box
.
height
/
2
&&
item
.
y
<
box
.
y
+
box
.
height
/
2
;
},
...
...
@@ -268,16 +220,20 @@ cc.Class({
let
addX
=
190
;
let
y
=
75
;
for
(
let
i
=
0
;
i
<
sonleis
.
length
;
i
++
)
{
let
data
=
sonleis
[
i
];
let
sonClone
=
cc
.
instantiate
(
son
);
sonClone
.
active
=
true
;
let
posX
=
x
+
addX
*
i
;
let
posY
=
y
;
sonClone
.
x
=
posX
;
sonClone
.
y
=
posY
;
sonClone
.
data
=
data
;
pg
.
view
.
setString
(
pg
.
view
.
find
(
sonClone
,
"
txt
"
),
data
.
title
);
box
.
addChild
(
sonClone
);
}
},
initBox
()
{
this
.
_boxItems
=
[];
//刷新子类
let
son
=
pg
.
view
.
find
(
this
,
"
box/box_0
"
);
let
box
=
pg
.
view
.
find
(
this
,
"
box
"
);
...
...
@@ -289,12 +245,15 @@ cc.Class({
let
y
=
-
62
;
for
(
let
i
=
0
;
i
<
sonleis
.
length
;
i
++
)
{
let
sonClone
=
cc
.
instantiate
(
son
);
let
data
=
sonleis
[
i
];
sonClone
.
data
=
data
;
sonClone
.
active
=
true
;
let
posX
=
x
+
addX
*
i
;
let
posY
=
y
;
sonClone
.
x
=
posX
;
sonClone
.
y
=
posY
;
box
.
addChild
(
sonClone
);
this
.
_boxItems
.
push
(
sonClone
);
}
},
initItems
()
{
...
...
@@ -309,11 +268,14 @@ cc.Class({
let
addY
=
-
90
;
for
(
let
i
=
0
;
i
<
sonleis
.
length
;
i
++
)
{
let
sonClone
=
cc
.
instantiate
(
son
);
let
data
=
sonleis
[
i
];
sonClone
.
data
=
data
;
sonClone
.
active
=
true
;
let
posX
=
x
+
addX
*
(
i
%
7
);
let
posY
=
y
+
addY
*
Math
.
floor
(
i
/
7
);
sonClone
.
x
=
posX
;
sonClone
.
y
=
posY
;
this
.
initButton
(
sonClone
);
box
.
addChild
(
sonClone
);
}
}
else
{
...
...
@@ -325,6 +287,8 @@ cc.Class({
let
arr
=
[
3
,
4
,
5
,
6
,
10
,
11
,
12
,
13
,
14
,
15
,
16
,
17
,
18
,
19
,
20
,
21
,
22
,
23
,
24
,
25
,
26
,
27
,
28
,
29
,
30
];
for
(
let
i
=
0
;
i
<
sonleis
.
length
;
i
++
)
{
let
sonClone
=
cc
.
instantiate
(
son
);
let
data
=
sonleis
[
i
];
sonClone
.
data
=
data
;
sonClone
.
active
=
true
;
let
posX
=
x
+
addX
*
(
arr
[
i
]
%
10
);
let
posY
=
y
+
addY
*
Math
.
floor
(
arr
[
i
]
/
10
);
...
...
@@ -332,11 +296,72 @@ cc.Class({
sonClone
.
y
=
posY
;
sonClone
.
scaleX
=
scale
;
sonClone
.
scaleY
=
scale
;
this
.
initButton
(
sonClone
);
box
.
addChild
(
sonClone
);
}
}
},
initButton
(
item
)
{
item
.
on
(
cc
.
Node
.
EventType
.
TOUCH_START
,
this
.
onStartItem
,
this
);
item
.
on
(
cc
.
Node
.
EventType
.
TOUCH_END
,
this
.
onEndItem
,
this
);
item
.
on
(
cc
.
Node
.
EventType
.
TOUCH_MOVE
,
this
.
onMoveItem
,
this
);
item
.
on
(
cc
.
Node
.
EventType
.
TOUCH_CANCEL
,
this
.
onCancelItem
,
this
);
},
onStartItem
(
touch
)
{
this
.
_startPos
=
cc
.
v2
(
touch
.
target
.
x
,
touch
.
target
.
y
);
let
touchPos
=
touch
.
getLocation
();
touch
.
target
.
x
=
touchPos
.
x
-
1280
/
2
;
touch
.
target
.
y
=
touchPos
.
y
-
720
/
2
;
},
onEndItem
(
touch
)
{
//检测碰撞
let
box
=
this
.
getCollider
(
touch
.
target
);
if
(
box
)
{
//成功 失败的判断 根据id
let
successed
=
box
.
data
.
child
.
some
(
dt
=>
dt
.
cardId
==
touch
.
target
.
data
.
cardId
);
if
(
successed
)
{
alert
(
"
成功
"
)
}
else
{
alert
(
"
失败
"
)
//碰撞失败退回原位置
touch
.
target
.
x
=
this
.
_startPos
.
x
;
touch
.
target
.
y
=
this
.
_startPos
.
y
;
}
}
else
{
//碰撞失败退回原位置
touch
.
target
.
x
=
this
.
_startPos
.
x
;
touch
.
target
.
y
=
this
.
_startPos
.
y
;
}
},
onMoveItem
(
touch
)
{
//获取到的location是 当前点击的位置 而不是按钮原本应该所在的位置。
let
touchPos
=
touch
.
getLocation
();
touch
.
target
.
x
=
touchPos
.
x
-
1280
/
2
;
touch
.
target
.
y
=
touchPos
.
y
-
720
/
2
;
},
onCancelItem
(
touch
)
{
console
.
log
(
touch
);
},
getCollider
(
item
)
{
for
(
let
i
=
0
;
i
<
this
.
_boxItems
.
length
;
i
++
)
{
if
(
this
.
checkCollider
(
item
,
this
.
_boxItems
[
i
]))
return
this
.
_boxItems
[
i
];
}
return
null
;
},
checkCollider
(
item
,
box
)
{
return
item
.
x
>
box
.
x
-
box
.
width
/
2
&&
item
.
x
<
box
.
x
+
box
.
width
/
2
&&
item
.
y
>
box
.
y
-
box
.
height
/
2
&&
item
.
y
<
box
.
y
+
box
.
height
/
2
;
},
// updateItem(item, data) {
// let img = pg.view.find(item, `img`);
...
...
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