【发布时间】:2019-11-21 22:07:19
【问题描述】:
我是 React 新手,所以我可能没有使用最佳实践。我正在尝试构建这个“Simon Says”游戏,但我一直试图在我的每个for 循环之间设置延迟,它们同时运行。我已经查看了其他解决方案,但它们似乎不适合我的。我也尝试过使用setTimeout,但这只是在延迟后立即播放所有动画。这是for 循环和我希望在两者之间有延迟的函数:
newRound() {
this.setState({
pcSequence: this.state.pcSequence.concat(
Math.floor(Math.random() * 4) + 1)
},() => {
this.state.pcSequence.forEach(element =>
this.startAnimations(element)
);
}
);
}
startAnimations(element) {
if (element == 1) {
this.activeBtn1(0);
} else if (element == 2) {
this.activeBtn2(1);
} else if (element == 3) {
this.activeBtn3(2);
} else if (element == 4) {
this.activeBtn4(3);
}
}
谢谢!!
【问题讨论】:
标签: reactjs settimeout delay