Skip to main content
Known Participant
July 1, 2022
Answered

Spinning wheel like Roullete

  • July 1, 2022
  • 1 reply
  • 700 views

Hi, 

I've made a simple game spinning wheel in Animate CC with HTML5 canvas platform. But I have no idea to make the wheel spin like roulette. Simply if button SPIN is pressed (mouse down event), the wheel will spin fast... Then if button SPIN is released (mouse up event) the wheel slowly decrease speed until it stop. I do hope there is kind someone solve this code.

Best regards...

    This topic has been closed for replies.
    Correct answer kglad

    if b is your button and w is your wheel:

     

    th

    this.slowRate = .1;
    this.initialRate = 10;
    this.spinFF = spinF.bind(this);
    this.slowFF = slowF.bind(this);
    this.b.addEventListener("mousedown",startSpinF.bind(this));
    this.b.addEventListener("pressup",startSlowF.bind(this));

    function startSpinF(){
    this.rotateSpeed = this.initialRate;
    createjs.Ticker.removeEventListener("tick", this.spinFF);
    createjs.Ticker.addEventListener("tick", this.spinFF);
    }
    function startSlowF(){
    createjs.Ticker.removeEventListener("tick", this.slowFF);
    createjs.Ticker.addEventListener("tick", this.slowFF);
    }
    function slowF(){
    this.rotateSpeed = Math.max(0,this.rotateSpeed-this.slowRate);
    if(this.rotateSpeed==0){
    createjs.Ticker.removeEventListener("tick", this.slowFF);
    }
    }

    function spinF(){
    this.w.rotation += this.rotateSpeed;
    }

    1 reply

    kglad
    Community Expert
    kgladCommunity ExpertCorrect answer
    Community Expert
    July 1, 2022

    if b is your button and w is your wheel:

     

    th

    this.slowRate = .1;
    this.initialRate = 10;
    this.spinFF = spinF.bind(this);
    this.slowFF = slowF.bind(this);
    this.b.addEventListener("mousedown",startSpinF.bind(this));
    this.b.addEventListener("pressup",startSlowF.bind(this));

    function startSpinF(){
    this.rotateSpeed = this.initialRate;
    createjs.Ticker.removeEventListener("tick", this.spinFF);
    createjs.Ticker.addEventListener("tick", this.spinFF);
    }
    function startSlowF(){
    createjs.Ticker.removeEventListener("tick", this.slowFF);
    createjs.Ticker.addEventListener("tick", this.slowFF);
    }
    function slowF(){
    this.rotateSpeed = Math.max(0,this.rotateSpeed-this.slowRate);
    if(this.rotateSpeed==0){
    createjs.Ticker.removeEventListener("tick", this.slowFF);
    }
    }

    function spinF(){
    this.w.rotation += this.rotateSpeed;
    }

    Known Participant
    July 1, 2022

    I've copied your code. I replaced b to spinBtn and w to wheel. I got this error :

    kglad
    Community Expert
    Community Expert
    July 2, 2022

    you're welcome (and i assume you restored that missing t from this.