Skip to main content
Known Participant
Jul 1, 2022 8:26 AM UTC
Answered

Spinning wheel like Roullete

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 is closed to new replies. Start a new post to keep the conversation going.
    kglad
    kgladCorrect answer
    Community Expert
    Jul 1, 2022 2:36 PM UTC

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

    6 replies

    kglad
    Community Expert
    kgladCommunity ExpertCorrect answer
    Community Expert
    Jul 1, 2022 2:36 PM UTC

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

    Translate
    Known Participant
    Jul 1, 2022 6:36 PM UTC

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

    Translate
    kglad
    Community Expert
    Community Expert
    Jul 2, 2022 12:31 AM UTC

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

    Translate