Commit 99131e78 authored by Tt's avatar Tt

拖动部分完成

parent 411b0a56
......@@ -386,7 +386,7 @@
"__id__": 2
},
"_children": [],
"_active": true,
"_active": false,
"_components": [
{
"__id__": 9
......@@ -802,7 +802,7 @@
"node": {
"__id__": 14
},
"_enabled": true,
"_enabled": false,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
......
......@@ -27,7 +27,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.initView();
this.initListener();
this.initEvent()
this.initGame();
}
// 一轮单词数量
private static Word_List_Len: number = 8;
......@@ -208,7 +207,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
getItemPosWidthByAns(ansArr, itemAnsArr, count) {
//根据总长度计算出需要预留的空间大小
let defaultPos = cc.v2(0, -270);
let defaultPos = cc.v2(0, -300);
let singleWordWidth = 220;
let orgPos = this.getTotalWordWidth(ansArr, singleWordWidth, defaultPos);
let itemWidth = itemAnsArr.length * singleWordWidth;
......@@ -223,7 +222,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
getWordPosByAns(ansArr, data) {
//根据总长度计算出需要预留的空间大小
let defaultPos = cc.v2(0, -270);
let defaultPos = cc.v2(0, -300);
let singleWordWidth = 220;
let orgPos = this.getTotalWordWidth(ansArr, singleWordWidth, defaultPos);
// 计算当前是第几个
......@@ -273,6 +272,11 @@ export default class SceneComponent extends MyCocosSceneComponent {
child.y = 0;
return child;
}
getWordBgByGroup(group) {
return this.wordBgList.filter(item => {
return item.data.group == group
})
}
collider(node) {
// 每个字母
let worldPos = cc.v2(node.x, node.y);
......@@ -303,8 +307,13 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
return groupId;
}
private currentItem: cc.Node;
onTouchStart(event) {
console.log('1')
let node = event.target;
this.currentItem = node;
this.startCurrentItemAni();
}
onTouchMove(event) {
let node = event.target;
......@@ -320,10 +329,25 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
onTouchEnd(event) {
let node = event.target;
this.stopCurrentItemAni();
this.currentItem = null;
// 跟字母区域进行碰撞检测
let groupId = this.collider(node);
// 获取当前待碰撞区域
if (!groupId && groupId != 0) {
if ((groupId || groupId == 0) && node.data[0].data.group == groupId) {
console.log(groupId)
// 正确了 需要处理效果
let nodes = node.data;
let targets = this.getWordBgByGroup(groupId);
nodes.forEach(item => {
let dt = item.data;
let target = targets.find(tr => tr.data.index == item.data.index);
this.wordToWordBg(item, target);
})
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);
} else {
let subX = node.x - node.orgPos.x;
let subY = node.y - node.orgPos.y;
node.x -= subX;
......@@ -332,46 +356,33 @@ export default class SceneComponent extends MyCocosSceneComponent {
nd.x -= subX;
nd.y -= subY;
})
} else {
// let data = colliderNode.data;
// console.log(JSON.stringify(data));
console.log(groupId)
// 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);
}
}
wordToWordBg(node, target) {
cc.tween(node).to(0.2, { x: target.x, y: target.y, scale: 0.85 })
.call(() => {
target.active = false;
}).start();
}
startCurrentItemAni() {
let childs = this.currentItem.data;
childs.forEach(child => {
cc.tween(child).to(0.15, { scaleX: 1.1, scaleY: 0.9 }).to(0.15, { scaleX: 1, scaleY: 1 }).delay(0.25).union().repeatForever().start();
})
}
stopCurrentItemAni() {
let childs = this.currentItem.data;
childs.forEach(child => {
cc.Tween.stopAllByTarget(child)
})
}
getBgNodeByGroupIndex(group, index) {
let groupNode = this.wordBgList.find(node => {
return node.data.group == group && node.data.index == index;
})
return groupNode;
}
private count: number;
initGame() {
}
startPlay() {
}
gameOver() {
}
updateLayer(layer, data) {
}
onTouchVoice(e) {
}
playLocalAudio(audioName) {
const audio = cc.find(`Canvas/res/audio/${audioName}`).getComponent(cc.AudioSource);
return new Promise((resolve, reject) => {
......
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