Commit 16f2c8f5 authored by Tt's avatar Tt

项目完成

parent 7e914c05
......@@ -802,7 +802,7 @@
"node": {
"__id__": 14
},
"_enabled": false,
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
......
......@@ -3,7 +3,10 @@ import { MyCocosSceneComponent } from "../script/MyCocosSceneComponent_hy01_danc
import pg from "./pg_hy01_danci";
const { ccclass, property } = cc._decorator;
enum WORD_TYPE {
TOUCH,
LINE
}
@ccclass
export default class SceneComponent extends MyCocosSceneComponent {
addPreloadImage() {
......@@ -180,7 +183,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
let child = this.getWordBgNodeByStr(str);
child.data = { count: count, group: i, index: m }
this.successGroupIds[`${i}`] = false;
let pos = this.getWordBgPosByAns(ansArr, child.data)
let pos = this.getWordBgPosByAns(ansArr, [str], child.data)
child.x = pos.x;
child.y = pos.y;
this.wordBgList.push(child);
......@@ -214,7 +217,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
count++;
let child = this.getWordNodeByStr(str);
child.data = { group: i, index: m, count: count };
let pos = this.getWordPosByAns(ansArr, child.data);
let pos = this.getWordPosByAns(ansArr, [str], child.data);
child.x = pos.x;
child.y = pos.y;
this.wordList.push(child)
......@@ -230,50 +233,93 @@ export default class SceneComponent extends MyCocosSceneComponent {
getItemPosWidthByAns(ansArr, itemAnsArr, count) {
//根据总长度计算出需要预留的空间大小
let defaultPos = cc.v2(0, -300);
let singleWordWidth = 220;
let orgPos = this.getTotalWordWidth(ansArr, singleWordWidth, defaultPos);
let itemWidth = itemAnsArr.length * singleWordWidth;
let orgPos = this.getTotalWordOrgPos(WORD_TYPE.TOUCH, ansArr, defaultPos);
let itemWidth = this.getItemWordWidth(WORD_TYPE.TOUCH, itemAnsArr);
let leftWidth = this.getLeftWidthByCount(WORD_TYPE.TOUCH, ansArr, count);
// 计算当前是第几个
let pos = cc.v2(0, 0);
pos.x = orgPos.x + count * singleWordWidth;
pos.x = orgPos.x + leftWidth + itemWidth / 2;
pos.y = orgPos.y;
if (itemAnsArr.length > 0) {
pos.x += itemWidth / 2 - singleWordWidth / 2;
// pos.x += itemWidth / 2 - singleWordWidth / 2;
}
return { pos: pos, width: itemWidth };
}
getWordPosByAns(ansArr, data) {
getWordPosByAns(ansArr, itemAnsArr, data) {
//根据总长度计算出需要预留的空间大小
let defaultPos = cc.v2(0, -300);
let singleWordWidth = 220;
let orgPos = this.getTotalWordWidth(ansArr, singleWordWidth, defaultPos);
// 计算当前是第几个
let orgPos = this.getTotalWordOrgPos(WORD_TYPE.TOUCH, ansArr, defaultPos);
let itemWidth = this.getItemWordWidth(WORD_TYPE.TOUCH, itemAnsArr);
let count = data.count;
let leftWidth = this.getLeftWidthByCount(WORD_TYPE.TOUCH, ansArr, count);
// 计算当前是第几个
let pos = cc.v2(0, 0);
pos.x = orgPos.x + count * singleWordWidth;
pos.x = orgPos.x + leftWidth + itemWidth / 2;
pos.y = orgPos.y;
return pos;
}
getWordBgPosByAns(ansArr, data) {
getWordBgPosByAns(ansArr, itemAnsArr, data) {
//根据总长度计算出需要预留的空间大小
let defaultPos = cc.v2(0, 60);
let singleWordWidth = 200;
let orgPos = this.getTotalWordWidth(ansArr, singleWordWidth, defaultPos);
let orgPos = this.getTotalWordOrgPos(WORD_TYPE.LINE, ansArr, defaultPos);
let itemWidth = this.getItemWordWidth(WORD_TYPE.LINE, itemAnsArr);
// 计算当前是第几个
let count = data.count;
let leftWidth = this.getLeftWidthByCount(WORD_TYPE.LINE, ansArr, count);
let pos = cc.v2(0, 0);
pos.x = orgPos.x + count * singleWordWidth;
pos.x = orgPos.x + leftWidth + itemWidth / 2;
pos.y = orgPos.y;
return pos;
}
getTotalWordWidth(ansArr, singleWordWidth, defaultPos) {
getTotalWordOrgPos(type: WORD_TYPE, ansArr, defaultPos) {
let wordStr = ansArr.join('')
let length = wordStr.length;
let totalWordWidth = length * singleWordWidth;
let totalWordWidth = 0;
wordStr.split('').forEach((s) => {
let w = this.getWordNodeWidth(type, s);
totalWordWidth += w;
})
let orgPos = cc.v2(-totalWordWidth / 2 + defaultPos.x, defaultPos.y);
return orgPos
}
getItemWordWidth(type: WORD_TYPE, ansArr) {
let wordStr = ansArr.join('')
let totalWordWidth = 0;
wordStr.split('').forEach((s) => {
let w = this.getWordNodeWidth(type, s);
totalWordWidth += w;
})
return totalWordWidth;
}
getLeftWidthByCount(type: WORD_TYPE, ansArr, count) {
let wordStr = ansArr.join('')
let totalWordWidth = 0;
wordStr.split('').forEach((s, i) => {
let w = this.getWordNodeWidth(type, s);
if (i >= count) return;
totalWordWidth += w;
})
return totalWordWidth;
}
getWordNodeWidth(type, str) {
const reg = /^[A-Z]+$/;
const lower = str.toLowerCase()
if (type === WORD_TYPE.TOUCH) {
let prefabNode = reg.test(str) ? pg.view.find(this.upper_word, `${lower}2`) : pg.view.find(this.lower_word, `${lower}`)
return prefabNode.width + 20;
} else {
let prefabNode = reg.test(str) ? pg.view.find(this.upper_shadow, `${lower}2_di`) : pg.view.find(this.lower_shadow, `${lower}_di`);
return prefabNode.width + 30;
}
}
getWordNodeByStr(str) {
const reg = /^[A-Z]+$/;
const lower = str.toLowerCase()
......
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