Commit 54933023 authored by limingzhe's avatar limingzhe

fix: debug

parent a8cb6846
No preview for this file type
...@@ -96,7 +96,13 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -96,7 +96,13 @@ export default class SceneComponent extends MyCocosSceneComponent {
let img = pg.view.find(this.layout_canvas, 'img'); let img = pg.view.find(this.layout_canvas, 'img');
pg.view.setNetImg(img, this.currentQuestion.bgItem.url, { w: 1220, h: 790 }, true).then(() => { pg.view.setNetImg(img, this.currentQuestion.bgItem.url, { w: 1220, h: 790 }, true).then(() => {
this.initTargets(img); this.initTargets(img);
if (this.current != 0) {
this.layout_target.children.forEach(nd => {
nd.opacity = 255
})
}
}) })
if (this.current == 0) { if (this.current == 0) {
...@@ -117,18 +123,25 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -117,18 +123,25 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
} }
initTargets(img) { initTargets(img) {
console.log('in initTargets')
this.layout_target.removeAllChildren(); this.layout_target.removeAllChildren();
let item_color = pg.view.find(this, 'item_color'); let item_color = pg.view.find(this, 'item_color');
let boxHeight = this.layout_canvas.height; // let boxHeight = this.layout_canvas.height;
let imgHeight = img.height; // let imgHeight = img.height;
let moveY = (boxHeight - imgHeight) / 2 // let moveY = (boxHeight - imgHeight) / 2
let arr = this.changepoints(this.currentQuestion, moveY);
this.layout_target.scale = img.scale;
this.layout_items.scale = img.scale;
let arr = this.changepoints(this.currentQuestion, img);
// 整体的坐标需要往中间下面进行计算。 // 整体的坐标需要往中间下面进行计算。
arr.forEach((ar) => { arr.forEach((ar) => {
let node = pg.view.clone(item_color); let node = pg.view.clone(item_color);
node.x = ar.pos.x; node.x = ar.pos.x;
node.y = ar.pos.y node.y = ar.pos.y;
node.data = ar; node.data = ar;
node.opacity = 0; node.opacity = 0;
node.removeComponent(cc.Sprite); node.removeComponent(cc.Sprite);
...@@ -316,18 +329,45 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -316,18 +329,45 @@ export default class SceneComponent extends MyCocosSceneComponent {
return { targetData, targetItem } return { targetData, targetItem }
} }
private changepoints(data, moveY) { private changepoints(data, bgImg) {
let scaleX = 1220 / data.bgItem.rect.width;
let scaleY = 790 / data.bgItem.rect.height; const rate = (bgImg.scale * bgImg.width) / data.bgItem.rect.width;
let scale = scaleX <= scaleY ? scaleX : scaleY; const scale = rate / bgImg.scaleY;
return data.hotZoneItemArr.map((item, idx) => { return data.hotZoneItemArr.map((item, idx) => {
let rect = item.rect; let rect = item.rect;
item.pos = {
x: (rect.x + (rect.width / 2)) * scale, item.pos = {};
y: -((rect.y + (rect.height / 2)) * scale) - moveY
} const rectNode = new cc.Node();
item.width = rect.width * scale; rectNode.name = 'rect' + data.index;
item.height = rect.height * scale; bgImg.addChild(rectNode);
const ctx = rectNode.addComponent(cc.Graphics);
// 矩形
ctx.lineWidth = 4;
ctx.strokeColor = cc.Color.BLACK;
ctx.fillColor = cc.Color.WHITE.setA(100);
// const scale = rate / bgImg.scaleY;
rectNode.width = rect.width * scale;
rectNode.height = rect.height * scale;
rectNode.x = -bgImg.width / 2 + rect.x * scale;
rectNode.y = bgImg.height / 2 - rect.height * scale - rect.y * scale;
rectNode.anchorX = rectNode.anchorY = 0;
ctx.rect(0, 0, rectNode.width, rectNode.height);
// ctx.stroke();
// ctx.fill();
item.width = rectNode.width;
item.height = rectNode.height;
const worldPos = bgImg.convertToWorldSpaceAR(cc.v2(rectNode.x + rectNode.width / 2, rectNode.y + rectNode.height / 2));
const newPos = this.layout_target.convertToNodeSpaceAR(worldPos);
item.pos.x = newPos.x;
item.pos.y = newPos.y;
// item.width = rect.width * scale;
// item.height = rect.height * scale;
return item; return item;
}) })
} }
...@@ -349,6 +389,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -349,6 +389,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
let text2 = pg.view.find(node, 'text_2'); let text2 = pg.view.find(node, 'text_2');
text1.active = false; text1.active = false;
text2.active = false; text2.active = false;
text.parent.scale = 1 / this.layout_items.scale;
pg.view.setColor(text, '#1D8B38') pg.view.setColor(text, '#1D8B38')
text.getComponent(cc.Label).fontSize = targetData.fontSize; text.getComponent(cc.Label).fontSize = targetData.fontSize;
......
import { width } from './../../../form/node_modules/@fortawesome/free-regular-svg-icons/faAddressCard.d';
class Emitter { class Emitter {
static instance; static instance;
static getInstance() { static getInstance() {
...@@ -292,13 +293,19 @@ let pg = { ...@@ -292,13 +293,19 @@ let pg = {
let scaleX = w / nw; let scaleX = w / nw;
let scaleY = h / nh; let scaleY = h / nh;
let scale = scaleX <= scaleY ? scaleX : scaleY; let scale = scaleX <= scaleY ? scaleX : scaleY;
node.width = nw * scale; // node.width = nw * scale;
node.height = nh * scale; // node.height = nh * scale;
node.scale = scale;
} else { } else {
let scaleX = w / nw; let scaleX = w / nw;
let scaleY = h / nh; let scaleY = h / nh;
node.width = nw * scaleX; let scale = scaleX <= scaleY ? scaleX : scaleY;
node.height = nh * scaleY;
// node.width = nw * scaleX;
// node.height = nh * scaleY;
node.scale = scale;
} }
node.active = nodeActive; node.active = nodeActive;
resolve({ w: nw, h: nh }); resolve({ w: nw, h: nh });
......
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