gpt4 book ai didi

javascript - 更改路径 onclick 颜色时打印文本

转载 作者:行者123 更新时间:2023-12-03 07:27:53 24 4
gpt4 key购买 nike

我正在尝试制作一款需要单击圆圈的游戏。当您单击每个圆圈时,它会改变颜色。我希望它在单击所有圆圈时说“恭喜”,但目前在按下一个圆圈后它会显示“恭喜”。知道如何解决这个问题吗?

var text = new PointText(view.center);
text.content = 'Congrats';
text.visible = false;
text.style = {
fontFamily: 'Courier New',
fontWeight: 'bold',
fontSize: 100,
fillColor: 'black',
justification: 'center'
}

for (l = 0; l < balls.length; l++) {
balls[l].onClick = function(event) {
counter++



this.fillColor = '#860d2b';
var areAnyCoral = false;
for (var j = 0; j < balls.length; j++) {
if (balls[j].fillColor === 'coral') {
areAnyCoral = true;
}
};
if (areAnyCoral === false) {
text.visible = true;
}

}

}

最佳答案

我认为您应该检查 text.visible 属性的计数器,而不是填充颜色。这有道理吗?

var counter = 0;
var ball1 = {
color: "notCoral"
};

var ball2 = {
color: "notCoral"
}

var balls = [ball1, ball2];

balls.forEach(function(ball) {
ball.onClick = function(event) {
if (ball.color == "notCoral") {
ball.color = "coral";
counter++;
}

if (counter == balls.length) {
text.visible = true;
}
}
});

关于javascript - 更改路径 onclick 颜色时打印文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35926079/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com