如果我理解正確的話,你可能想要這樣的東西;如果沒有姿勢和標簽,則全局變量shownImageSet將“保持”到最后一個值。 不需要flag/flag2變量。 // ... initialization code elided ...let shownImageSet = 0;function drawImages() { // Select image set based on pose + label if (pose) { if (label == "HowMuchCanYouSee") { shownImageSet = 1; } if (label == "Orochimaru") { shownImageSet = 2; } } if (shownImageSet) { // Need to show something? const eyeR = pose.rightEye; const eyeL = pose.leftEye; const d = dist(eyeR.x, eyeR.y, eyeL.x, eyeL.y); if (shownImageSet == 1) { image(img1, eyeL.x - d / 2, eyeL.y - d / 2, d, d); image(img1, eyeR.x - d / 2, eyeR.y - d / 2, d, d