Editing initTargets function - unsubscribe&resubscribe
This commit is contained in:
parent
79b023829f
commit
9c9865f149
|
@ -54,9 +54,9 @@ function keyPressed() {
|
|||
// reset score and targets
|
||||
gun.remainingShots = TOT_SHOTS;
|
||||
score.shotLeft = TOT_SHOTS;
|
||||
|
||||
score.score = 0;
|
||||
|
||||
initTargets();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,8 +65,14 @@ function initTargets() {
|
|||
// Create new targets from the factory
|
||||
// Remember to unsubscribe the previous targets and to subscribe the new ones
|
||||
const factory = TargetFactory.getInstance();
|
||||
gun.unsubscribeAll();
|
||||
|
||||
targets = factory.getRandomTargets(MAX_TARGETS, TARGET_WIDTH, 200);
|
||||
gun.subscribe(score);
|
||||
for (let target of targets) {
|
||||
gun.subscribe(target);
|
||||
target.subscribe(score);
|
||||
}
|
||||
}
|
||||
|
||||
// Do not touch these
|
||||
|
|
Loading…
Reference in New Issue
Block a user