我正在为画布制作一个多项选择测验游戏,用户可以在其中上传自己的图像以获得多项选择答案。
When the next question is selected, the variables for the next question are got from a javascript array, including filepath for the image.
我遇到的问题是,通常在第一次测验尝试时,图像有时不会及时加载以在画布上绘制。我正在尝试通过确保始终绘制图像答案来提高测验画布方面的性能。
帮助将不胜感激。在画布上绘制图像的代码如下。
//else if answer type is image answer
else if(answertype == "image"){
answerbg.src = "./resources/imageaudiovideoanswerbg.png";
eventstate = 'imageaget';
if (answerbg.complete) {
context.drawImage(answerbg, 0, 280);
context.drawImage(imagefilea,75,285);
context.drawImage(imagefileb,375,285);
context.drawImage(imagefilec,75,591);
context.drawImage(imagefiled,375,591);
}
else {
answerbg.onload = function () {
context.drawImage(answerbg, 0, 280);
context.drawImage(imagefilea,75,285);
context.drawImage(imagefileb,375,285);
context.drawImage(imagefilec,75,591);
context.drawImage(imagefiled,375,591);
};
}
}