Please help, I don’t know how to clear Interval when i choose good or wrong answer. Without choosing answer Interval clear when time goes to 0. When you choose a good option or a bad one, it moves to the next artboard, but the old interval still remains in the computer’s memory. I am not a coding specialist, which can be seen from my coding method… Game made in Adobe Animate.
createjs.Touch.enable(stage);
stage.enableMouseOver();
this.stop();
console.log("enter game")
let selected = [];
let finalMove = null;
let numberOfSec = 20;
//let level = 1;
//let score = 0;
this.timer.text = numberOfSec;
this.score.text = counterWin;
this.timer.visible = true;
this.timeplace.visible = false;
const timerInterval = setInterval(() => {
numberOfSec--
this.timer.text = numberOfSec;
if(numberOfSec==5){
this.timer.visible = true;
this.timeplace.visible = true;
createjs.Sound.play('clock');
console.log("clock 5 to 0")
}
if(numberOfSec==0){
this.gotoAndStop('next1')
clearInterval(numberOfSec);
console.log(numberOfSec);
console.log("enter to page next1")
createjs.Sound.stop();
}
},1000)
const elements1 = [
this.mc1,
this.mc2,
this.mc3,
this.mc4,
this.mc5,
]
const places = [
this.card1,
this.card2,
this.card3,
this.card4,
this.card5,
];
shuffle(places);
elements1.forEach((element, index) => {
element.x = places[index].x;
element.y = places[index].y;
})
function shuffle(a) {
let j, x, i;
for (i = a.length - 1; i > 0; i--) {
j = Math.floor(Math.random() * (i + 1));
x = a[i];
a[i] = a[j];
a[j] = x;
}
return a;
}
//var clear = clearInterval(numberOfSec);
var root = this;
elements1.forEach(element => {
element.addEventListener('click', (event) =>{
if (event.currentTarget.name === 'mc5'){
console.log("GOOD")
counterWin+=2;
//clearInterval(numberOfSec);
//root.clear;
console.log(clear);
this.score.text = counterWin;
//createjs.Sound.stop();
createjs.Sound.play('good');
this.play();
createjs.Sound.stop();
console.log(counterWin);
}else{
console.log("WRONG")
createjs.Sound.play('wrong');
//clearInterval(numberOfSec);
//root.clear;
createjs.Sound.stop();
this.play();
}
});
});