Commit 6f8602ef authored by Tt's avatar Tt

处理图片缩小偏移量问题

parent dfa8a75b
......@@ -95,7 +95,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.img_dengpao.opacity = 100;
let img = pg.view.find(this.layout_canvas, 'img');
pg.view.setNetImg(img, this.currentQuestion.bgItem.url, { w: 1220, h: 790 }, true)
pg.view.setNetImg(img, this.currentQuestion.bgItem.url, { w: 1220, h: 790 }, true).then(() => {
this.initTargets(img);
})
if (this.current == 0) {
this.playLocalAudio('opendoor')
......@@ -109,16 +111,20 @@ export default class SceneComponent extends MyCocosSceneComponent {
}).start();
cc.tween(img_door_right).to(1.6, { x: 1000 }).start();
}
this.initTargets();
}
initTargets() {
initTargets(img) {
this.layout_target.removeAllChildren();
let item_color = pg.view.find(this, 'item_color');
let arr = this.changepoints(this.currentQuestion);
let boxHeight = this.layout_canvas.height;
let imgHeight = img.height;
let moveY = (boxHeight - imgHeight) / 2
let arr = this.changepoints(this.currentQuestion, moveY);
// 整体的坐标需要往中间下面进行计算。
arr.forEach((ar) => {
let node = pg.view.clone(item_color);
node.x = ar.pos.x;
node.y = ar.pos.y;
node.y = ar.pos.y
node.data = ar;
node.removeComponent(cc.Sprite);
this.layout_target.addChild(node)
......@@ -281,8 +287,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 检测碰撞成功需要重新编写
checkSuccess(node) {
let question = this.currentQuestion
let arr = this.changepoints(question)
// 左上角坐标
let targetData = null;
let minDis = 999999;
......@@ -298,7 +302,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
return targetData
}
private changepoints(data) {
private changepoints(data, moveY) {
let scaleX = 1220 / data.bgItem.rect.width;
let scaleY = 790 / data.bgItem.rect.height;
let scale = scaleX <= scaleY ? scaleX : scaleY;
......@@ -306,7 +310,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
let rect = item.rect;
item.pos = {
x: (rect.x + (rect.width / 2)) * scale,
y: -((rect.y + (rect.height / 2)) * scale)
y: -((rect.y + (rect.height / 2)) * scale) - moveY
}
item.width = rect.width * scale;
item.height = rect.height * scale;
......
export const defaultData =
{
"npcTitle": "",
"npcAudio": "http://staging-teach.cdn.ireadabc.com/3b2c8fe71c2d8334e0f39bdd6ca7b920_l.mp3",
"npcAudioName": "把正确的单-迅捷文字转语音-1703127015594.mp3",
"npcAudioEnd": "http://staging-teach.cdn.ireadabc.com/062790e2adc90579dc17b538b15afe8f_l.mp3",
"npcAudioEndName": "太棒了恭-迅捷文字转语音-1703127029111.mp3",
"questions": [
{
"options": [],
"hotZoneFontObj": {
"size": 50,
"name": "BRLNSR_1",
"color": "#8f3758"
},
"bgItem": {
"url": "http://staging-teach.cdn.ireadabc.com/f8742e7b03509739c2d623382d576b4d.png",
"rect": {
"x": 120.77634194831012,
"y": 0,
"width": 850.4473161033798,
"height": 355
}
},
"hotZoneItemArr": [
{
"index": 0,
"text": "child",
"itemType": "text",
"fontSize": 50,
"fontName": "BRLNSR_1",
"fontColor": "#8f3758",
"fontScale": 0.853125,
"imgScale": 1,
"mapScale": 0.853125,
"rect": {
"x": 272.96,
"y": 33.06,
"width": 133.99,
"height": 55.68
}
},
{
"index": 1,
"text": "curly",
"itemType": "text",
"fontSize": 50,
"fontName": "BRLNSR_1",
"fontColor": "#8f3758",
"fontScale": 0.853125,
"imgScale": 1,
"mapScale": 0.853125,
"rect": {
"x": 494.83,
"y": 18.27,
"width": 111.38,
"height": 69.61
}
},
{
"index": 2,
"text": "lady",
"itemType": "text",
"fontSize": 50,
"fontName": "BRLNSR_1",
"fontColor": "#8f3758",
"fontScale": 0.853125,
"imgScale": 1,
"mapScale": 0.853125,
"rect": {
"x": 327.77,
"y": 69.61,
"width": 174.02,
"height": 174.02
}
},
{
"index": 3,
"text": "straight",
"itemType": "text",
"fontSize": 50,
"fontName": "BRLNSR_1",
"fontColor": "#8f3758",
"fontScale": 0.853125,
"imgScale": 1,
"mapScale": 0.853125,
"rect": {
"x": 676.68,
"y": 60.91,
"width": 174.02,
"height": 174.02
}
},
{
"index": 4,
"text": "guy",
"itemType": "text",
"fontSize": 50,
"fontName": "BRLNSR_1",
"fontColor": "#8f3758",
"fontScale": 0.853125,
"imgScale": 1,
"mapScale": 0.853125,
"rect": {
"x": 252.95,
"y": 180.11,
"width": 174.02,
"height": 174.02
}
},
{
"index": 5,
"text": "colorful",
"itemType": "text",
"fontSize": 50,
"fontName": "BRLNSR_1",
"fontColor": "#8f3758",
"fontScale": 0.853125,
"imgScale": 1,
"mapScale": 0.853125,
"rect": {
"x": 520.07,
"y": 180.11,
"width": 174.02,
"height": 174.02
}
}
]
}
],
"bgItem": "",
"hotZoneItemArr": []
}
let mc = {
"npcTitle": "exit", "npcAudio": "http://staging-teach.cdn.ireadabc.com/5f4e4c72671607bb35d1ecd1d291f238_l.mp3",
"npcAudioName": "boom_dg28_drag.mp3",
"npcAudioEnd": "http://staging-teach.cdn.ireadabc.com/289fe0a6d9893519c3fb5993b86b6fe9_l.mp3",
......
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