Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to stop in 1 direction? #54

Open
richieteh94 opened this issue Sep 14, 2018 · 3 comments
Open

Is there a way to stop in 1 direction? #54

richieteh94 opened this issue Sep 14, 2018 · 3 comments

Comments

@richieteh94
Copy link

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
Copy link
Author

richieteh94 commented Sep 14, 2018

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;
    }
  }

@tedwong
Copy link

tedwong commented Mar 21, 2019

@richieteh94 May I know which line of codes?

@richieteh94
Copy link
Author

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants