Commit 8bb16561 authored by 范雪寒's avatar 范雪寒

fix: 图片选项处理

parent 8f88565b
...@@ -867,32 +867,24 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -867,32 +867,24 @@ export class PlayComponent implements OnInit, OnDestroy {
bg.addChild(picBg); bg.addChild(picBg);
this.picBgArr.push(picBg); this.picBgArr.push(picBg);
const rightBg = new MySprite(this.ctx); const rightBg = new MySprite(this.ctx);
rightBg.init(this.images.get('pic_right')); rightBg.init(this.images.get('pic_right'));
rightBg.x = picBg.x; picBg.addChild(rightBg);
rightBg.y = picBg.y;
bg.addChild(rightBg, 1);
rightBg.visible = false; rightBg.visible = false;
picBg['rightBg'] = rightBg; picBg['rightBg'] = rightBg;
const wrongBg = new MySprite(this.ctx); const wrongBg = new MySprite(this.ctx);
wrongBg.init(this.images.get('pic_wrong')); wrongBg.init(this.images.get('pic_wrong'));
wrongBg.x = picBg.x; picBg.addChild(wrongBg);
wrongBg.y = picBg.y;
bg.addChild(wrongBg, 1);
wrongBg.visible = false; wrongBg.visible = false;
picBg['wrongBg'] = wrongBg; picBg['wrongBg'] = wrongBg;
const textKey = 'text_' + keyArr[i]; const textKey = 'text_' + keyArr[i];
const title = new MySprite(this.ctx); const title = new MySprite(this.ctx);
title.init(this.images.get(textKey)); title.init(this.images.get(textKey));
title.x = picBg.x; title.y = -picBg.height / 2 + 39;
title.y = picBg.y - picBg.height / 2 + 39; picBg.addChild(title);
bg.addChild(title);
this.answerTitleArr.push(title); this.answerTitleArr.push(title);
} }
...@@ -2141,7 +2133,6 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -2141,7 +2133,6 @@ export class PlayComponent implements OnInit, OnDestroy {
this.textBgArr[i].wrongBg.visible = false; this.textBgArr[i].wrongBg.visible = false;
if (this.answerLabelArr[i] && answerArr[i].text) { if (this.answerLabelArr[i] && answerArr[i].text) {
this.answerLabelArr[i].text = answerArr[i].text; this.answerLabelArr[i].text = answerArr[i].text;
this.textBgArr[i].visible = true;
} else { } else {
this.answerLabelArr[i].text = ''; this.answerLabelArr[i].text = '';
this.textBgArr[i].visible = false; this.textBgArr[i].visible = false;
...@@ -2168,14 +2159,34 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -2168,14 +2159,34 @@ export class PlayComponent implements OnInit, OnDestroy {
this.questionPicRect.visible = false; this.questionPicRect.visible = false;
} }
let maxAnswerLength = 4;
for (let i = 3; i >= 0; i--) {
if (!answerArr[i].pic_url) {
maxAnswerLength--;
} else {
break;
}
}
const picLen = 206; const picLen = 206;
for (let i = 0; i < 4; i++) { for (let i = 0; i < 4; i++) {
const picBg = this.picBgArr[i]; const picBg = this.picBgArr[i];
picBg.removeChildren(); const oldPic = picBg['pic'];
if (oldPic) {
picBg.removeChild(oldPic);
picBg['pic'] = null;
}
picBg.wrongBg.visible = false; picBg.wrongBg.visible = false;
picBg.rightBg.visible = false; picBg.rightBg.visible = false;
const w = 1020;
const offX = -this.questionBg.width / 2 + 75
const picBgW = 236;
const disW = (w - picBgW * maxAnswerLength) / 3;
picBg.x = offX + picBg.width / 2 + i * (picBgW + disW);
picBg.x = ((i + 1) / (maxAnswerLength + 1) - 1 / 2) * (this.questionBg.width);
const picUrl = answerArr[i].pic_url; const picUrl = answerArr[i].pic_url;
if (picUrl) { if (picUrl) {
const pic = new MySprite(this.ctx); const pic = new MySprite(this.ctx);
...@@ -2183,10 +2194,11 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -2183,10 +2194,11 @@ export class PlayComponent implements OnInit, OnDestroy {
pic.y = 35; pic.y = 35;
pic.setScaleXY(getMinScale(pic, picLen)); pic.setScaleXY(getMinScale(pic, picLen));
picBg.addChild(pic); picBg.addChild(pic);
picBg['pic'] = pic;
} else {
picBg.visible = false;
} }
} }
} }
......
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