I’m building a slot game, one line with three reel, using CocosCreator and Typescript.
There is an already built auto-spin function once start, it will spin the reel infinite times. The spin will only stop once user click the manual spin button.
I wish to set a default limit for the auto-play function in my slot game, so that once it reach the limit, the reel stop spinning. I tried to change some of the code before but unfortunately I not manage to make it. Below is the original code, I just selected the auto spin code from entire code base.
I tried to add for loop statement but it can’t work as well:
for (var i=0; i<3; i++) {
this.scheduleOnce(this.spinTheReelsAgain ,(durations[this.reels.length - i] + 0.2) );
}
Your help will be much appreciated.
/** using for auto spin */
//@property(CustomButton)
autoSpin:CustomButton = null;
rollingCounts:number = 0;
stopUpdate:boolean = true;
spincontroller:SpinController;
gameController:GameController;
public autoSpinCall() {
}
/**
* start or stop spin
*/
public reelspins() {
SoundManager.getInstance().stopSoundEffects();
SoundManager.getInstance().playSoundEffect(SoundManager.SOUND.SPIN_START);
this.gameController.spinCounterLabel.node.opacity = 0;
this.gameController.stopWinnerTextAnim();
this.isSpinStart = !this.isSpinStart;
if (ConfigManager.getInstance().seletedGamePlugin.gameOnReelSpinStarted) {
ConfigManager.getInstance().seletedGamePlugin.gameOnReelSpinStarted();
}
this.gameController.startSpin.disableButton();
this.gameController.startSpin.showDollerIcon(false);
this.schedule(this.reelCountUpdate,0.1);
const updateSpin = (reel, index) => {
reel.stopAnimationTime = 0.0;
reel.stopAnimation();
reel.node.stopAllActions();
reel.currentSpinningState=reel.ReelSpinStateEnum.IDLE;
const spinStartWithDelay = cc.callFunc(() => {
if (reel.currentSpinningState==reel.ReelSpinStateEnum.IDLE) {
reel.startSpin();
}
}, this);
const duration = this.gameController.startSpin.isTurboPlayStart ? this.reelTurboEndAnimationDurations[index] : this.reelEndAnimationDurations[index];
reel.node.runAction(cc.sequence(cc.delayTime(duration),spinStartWithDelay));
};
this.reels.forEach(updateSpin.bind(this));
this.gameController.hideButtonsOnSpinClick();
}
// if autospin -> spin the reels again
this.unschedule(this.spinTheReelsAgain);
this.scheduleOnce(this.spinTheReelsAgain ,(durations[this.reels.length - 1] + 0.2));
}
/**
* Start spinning if Auto/Turbo play is enable
*/
public spinTheReelsAgain(dt) {
this.gameController.startSpinningWithDelay(0.15);
}
public balanceCreditWin() {
this.isWinAnimationStart=false;
PlayerDataManager.getInstance().spinFinished();
}
public updateReelContainerLayout() {
// const layout: cc.Layout = this.reelContainer.getComponent(cc.Layout);
// layout.updateLayout();
}