Skip to main content
Known Participant
September 20, 2022
Answered

click to reach 100% with a progress bar / html5 canvas

  • September 20, 2022
  • 1 reply
  • 784 views

Hi,

I would like to design something that you often see in games.

It is a matter of clicking a certain number of times on a button which is on the scene so that the bar reaches 100%.

 

By clicking the bar gradually fills up to 100%. If you stop clicking, the bar gradually empties.

Once reached 100%, we go to the next frame automatically :

I've been thinking but can't see how to create something like this using html5 canvas?
Do you have any idea please?

 

    This topic has been closed for replies.
    Correct answer kglad

    create a bar movieclip that contains a fill movieclip (with bottom or left scale point) and a button b:

     

    var emptyRate = -.005;  // more neg, quicker it empties
    var fillRate = .1;  // more pos, quicker it fills
    this.bar.fill.scaleY = 0;
    var tl = this;

    this.b.addEventListener("click",clickF);
    createjs.Ticker.addEventListener("tick", tickF);


    function clickF(){
    fillF(fillRate);
    }
    function tickF(){
    fillF(emptyRate);
    }

    function fillF(amt){
    tl.bar.fill.scaleY+= amt;
    if(tl.bar.fill.scaleY<0){
    tl.bar.fill.scaleY = 0;
    } else {
    if(tl.bar.fill.scaleY>=1){
    tl.bar.fill.scaleY = 1
    tl.b.removeEventListener("click",clickF);
    createjs.Ticker.removeEventListener("tick", tickF);
    // do whatever. bar filled
    }
    }
    }

    1 reply

    JoãoCésar17023019
    Community Expert
    Community Expert
    September 20, 2022

    Hi.

     

    Maybe this prototype is what you're looking for:

    https://github.com/joao-cesar/adobe/tree/master/animate%20cc/html5_canvas/meter_game

     

    Please let us know if that's unnecessarily complex.

     

    Regards,

    JC

    Known Participant
    September 20, 2022

    Thank you for the quick reply. It's really excellent but maybe a bit too complex.

     

    I would just like the bar at the beginning to be empty and fill on clicking to get to 100%.
    The user could not lose. If we reach 100% we go to the next image like your creation which is great.


    And it shouldn't be too hard to fill the bar when the button is clicked. Because there it's quite hard it's very arcade.