Commit 23b72a83 authored by Chen Jiping's avatar Chen Jiping

fix:增加单词动画

parent f56ac129
...@@ -244,6 +244,64 @@ export class Exercises { ...@@ -244,6 +244,64 @@ export class Exercises {
return answer; return answer;
} }
getTextView2(letterArr){
let getLabel =(letter, fontColor)=>{
const label = new Label();
label.text = letter;
label.textAlign = 'center';
label.fontSize = 88;
label.fontName = "MMB";
label.fontColor = fontColor;
label.setScaleXY(this.scaleX);
label.refreshSize();
label.y = label.getBoundingBox().height / 2;
return label;
}
const bg = new ShapeRect();
let h = 0;
let w = 0;
let x = 0;
for (let i = 0; i < letterArr.length; ++i) {
let letter = letterArr[i];
if(!letter){
continue;
}
let fontColor = "#000000";
if (letter.isFill == '1') {
fontColor = "#c8161d";
}
for(let j = 0; j < letter.val.length; ++ j){
let label = getLabel(letter.val.charAt(j), fontColor);
label.x = x;
x += label.getBoundingBox().width;
h = label.getBoundingBox().height;
w += label.getBoundingBox().width;
bg.addChild(label);
}
}
bg.alpha = 0;
bg.visible = false;
bg.setSize(w, h);
return bg;
}
getAnswerView(answerBg, answerData) { getAnswerView(answerBg, answerData) {
let w = 386 * this.scaleX; let w = 386 * this.scaleX;
...@@ -274,9 +332,10 @@ export class Exercises { ...@@ -274,9 +332,10 @@ export class Exercises {
answerBg.addChild(line); answerBg.addChild(line);
answerBg.line = line; answerBg.line = line;
let text = this.getTextView(answerData.letterArr); let text = this.getTextView2(answerData.letterArr);
text.x = (w - text.getBoundingBox().width) / 2; text.x = (w - text.getBoundingBox().width) / 2;
text.y = h / 2 - 195 * this.scaleY + 325 * this.scaleY + text.getBoundingBox().height / 2; //text.y = h / 2 - 195 * this.scaleY + 325 * this.scaleY + text.getBoundingBox().height / 2;
text.y = h / 2 - 195 * this.scaleY + 325 * this.scaleY;
text.alpha = 0; text.alpha = 0;
answerBg.addChild(text); answerBg.addChild(text);
answerBg.text = text; answerBg.text = text;
...@@ -421,14 +480,12 @@ export class Exercises { ...@@ -421,14 +480,12 @@ export class Exercises {
if (this.leftAnswer.line) { if (this.leftAnswer.line) {
this.leftAnswer.line.alpha = 1; this.leftAnswer.line.alpha = 1;
this.leftAnswer.text.visible = false;
this.leftAnswer.text.alpha = 0;
} }
if (this.rightAnswer.line) { if (this.rightAnswer.line) {
this.rightAnswer.line.alpha = 1; this.rightAnswer.line.alpha = 1;
this.rightAnswer.text.visible = false;
this.rightAnswer.text.alpha = 0;
} }
this.curCard = this.frontCard; this.curCard = this.frontCard;
...@@ -438,4 +495,31 @@ export class Exercises { ...@@ -438,4 +495,31 @@ export class Exercises {
} }
textAnimal(text, callback = null){
let labelArr = text.children;
const animal = (label, index) => {
tweenChange(label, {y : label.y - 12 * this.scaleY} , 0.08, () => {
let i = index + 1;
if(labelArr[i]){
animal(labelArr[i], i);
}
tweenChange(label, {y : label.y + 16 * this.scaleY}, 0.08, () => {
tweenChange(label, {y : label.y - 4 * this.scaleY}, 0.04, callback);
});
});
}
animal(labelArr[0], 0);
}
} }
\ No newline at end of file
...@@ -951,19 +951,21 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -951,19 +951,21 @@ export class PlayComponent implements OnInit, OnDestroy {
return; return;
} }
this.canTouch = false;
if (item.line) { if (item.line) {
if(item.line.alpha == 1){ if(item.line.alpha == 1){
item.line.alpha = 0; item.line.alpha = 0;
item.text.visible = true;
tweenChange(item.text, { alpha: 1 }, 0.2, () => { this.curExer.textAnimal(item.text, ()=>{
jelly(item.text); this.canTouch = true;
}); })
} }
else{ else{
tweenChange(item.text, { alpha: 1 }, 0.2, () => { this.curExer.textAnimal(item.text, ()=>{
jelly(item.text); this.canTouch = true;
}); })
this.curAudio = this.playAudio(this.curExer.data.leftAnswer.audioUrl, true); this.curAudio = this.playAudio(this.curExer.data.leftAnswer.audioUrl, true);
} }
} }
...@@ -977,18 +979,21 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -977,18 +979,21 @@ export class PlayComponent implements OnInit, OnDestroy {
return; return;
} }
this.canTouch = false;
if (item.line) { if (item.line) {
if(item.line.alpha == 1){ if(item.line.alpha == 1){
item.line.alpha = 0; item.line.alpha = 0;
item.text.visible = true;
this.curExer.textAnimal(item.text, ()=>{
this.canTouch = true;
})
tweenChange(item.text, { alpha: 1 }, 0.2, () => {
jelly(item.text);
});
} }
else{ else{
tweenChange(item.text, { alpha: 1 }, 0.2, () => { this.curExer.textAnimal(item.text, ()=>{
jelly(item.text); this.canTouch = true;
}); })
this.curAudio = this.playAudio(this.curExer.data.rightAnswer.audioUrl, true); this.curAudio = this.playAudio(this.curExer.data.rightAnswer.audioUrl, true);
} }
} }
......
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