CrazyTim / spin-wheel

An easy to use, themeable component for randomising choices and prizes.
https://crazytim.github.io/spin-wheel/examples/themes
MIT License
203 stars 53 forks source link

Roulette Wheel to Spin constantly #3

Closed ayush-lal closed 3 years ago

ayush-lal commented 3 years ago

Is there a way to trigger the roulette wheel to spin automatically and to never stop?

Im guessing this function needs to be called but struggling to figure it all out...

spin(speed) {

    const newSpeed = this.rotationSpeed + util.getRandomInt(speed * 0.85, speed * 0.15);

    this.setRotationSpeed(newSpeed);

    this.onSpin({
      event: 'spin',
      direction: this.rotationDirection,
      rotationSpeed: this.rotationSpeed,
    });

}
CrazyTim commented 3 years ago

Hey @ayush-lal,

this.rotationSpeed controls how fast the wheel is spinning, so you could just comment out this line:

// Decrease rotation (simulate drag):
this.rotationSpeed += (this.rotationResistance * delta) * this.rotationDirection;
ayush-lal commented 3 years ago

Thanks heaps! Do you know how I could go about triggering the Roulette Wheel to spin automatically as soon as the page has loaded?

CrazyTim commented 3 years ago

Try this:

wheel.init({
  settings,
  rotationResistance: 0, // 1. Ensure the spin won't slow down over time.
});
wheel.setRotationSpeed(30); // 2. Spin the wheel, speed 30.