Search code examples
javascripthtmlcanvaseaseljsstage

How do I create a "stage.update ()" exclusively for the object?


On my screen I have 10 images and 6 texts. I know that every time you call "stage.update()" is redesigned view screen.

I have only two objects that need constant "stage.update ()". The first is a chronometer that needs every second to update a text and the second is an image that can be dragged around the screen.

How do I create a "stage.update ()" exclusively for the object?


Attempts:

  1. I made an array of "stage" for a single canvas:

    canvas = document.getElementsByTagName ('canvas') [0];
    stage['full'] = new createjs.Stage(canvas);
    stage['chronometer'] = new createjs.Stage(canvas);   
    

    The problem that when executed, one cancels the other:

    stage ['full']. update ();
    stage ['chronometer']. update (); 
    
  2. I tried to create Container.

    containerTest = new createjs.Container(); 
    stage.addChild(containerTest);  
    

    Problem? Could not update only what is in the container.


Solution

  • With the ticker and a counter, i think you can do your stuff:

    var counter = 0;
    createjs.Ticker.addEventListener("tick", handleTick);
    var chronometer = ...
    chronometer.cache(xChrono,yChrono,widthChrono,heightChrono);
    
    function handleTick(event) {
       // handle your drag and drop
       // ...
       if (counter == maxValue) { // maxValue = 1000 / createjs.Ticker.getInterval()
           // redraw your chronometer
           // ...
           counter = 0;
           chronometer.updateCache();
       } else {
           counter++;
       }
       stage.update();
    }