jQuery-SlotMachine icon indicating copy to clipboard operation
jQuery-SlotMachine copied to clipboard

Is there a way to stop in 1 direction?

Open richieteh94 opened this issue 7 years ago • 3 comments

I set the spin direction is down and when stop sometimes the animation will goes up, is there a way to make the slot just go forward to stop?

richieteh94 avatar Sep 14 '18 01:09 richieteh94

I've figured out myself. I add a code block between the stop function in the slotmachine.js (Added in after the prevent jumping code block)

{
    key: 'stop',
    value: function stop(onStop) {
      var _this4 = this;

      if (!this.running || this.stopping) {
        return this.nextActive;
      }

      this.running = true;
      this.stopping = true;

      if (!Number.isInteger(this.nextActive)) {
        // Get random or custom element
        this.nextActive = this.custom;
      }

      // Check direction to prevent jumping
      if (this._isGoingBackward()) {
        this._resetPosition(this.bounds.firstToLast);
      } else if (this._isGoingForward()) {
        this._resetPosition(this.bounds.lastToFirst);
      }

      // Stop in a goodway <--###  Added code(Start)
      if (this.bounds.key == 'up') {
        this._resetPosition(this.bounds.lastToFirst);
      } else if (this.bounds.key == 'down') {
        this._resetPosition(this.bounds.firstToLast);
      }
      //<--###  Added code(End)

      // Update last choosen element index
      this.active = this.nextActive;

      // Perform animation
      var delay = this._getDelayFromSpins(1);
      // this.delay = delay;
      this._changeTransition(delay);
      this._animationFX = FX_STOP;
      this._changeTransform(this.getTileOffset(this.active));
      raf(function () {
        _this4.stopping = false;
        _this4.running = false;
        _this4.nextActive = null;

        if (typeof _this4.onComplete === 'function') {
          _this4.onComplete(_this4.active);
        }

        if (typeof onStop === 'function') {
          onStop.apply(_this4, [_this4.active]);
        }
      }, delay);

      return this.active;
    }
  }

richieteh94 avatar Sep 14 '18 09:09 richieteh94

@richieteh94 May I know which line of codes?

tedwong avatar Mar 21 '19 03:03 tedwong

@tedwong I can't access the code, but what i can tell the code is

// Stop in a goodway <--### Added code(Start) if (this.bounds.key == 'up') { this._resetPosition(this.bounds.lastToFirst); } else if (this.bounds.key == 'down') { this._resetPosition(this.bounds.firstToLast); } //<--### Added code(End)

You can see on the above code snippet

richieteh94 avatar Mar 21 '19 03:03 richieteh94