Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

after i at a click handler trigger setpaused i can not listen trick callback anymore #975

Open
lemonpigpig opened this issue Aug 10, 2018 · 1 comment
Labels

Comments

@lemonpigpig
Copy link

lemonpigpig commented Aug 10, 2018

version:createjs-2015.11.26.min.js

createjs.Ticker.on('tick', function(event) {
        var alpha, red, redNum, beginX, duration, radius, toX;
        // if (event.paused) {
        //   return;
        // }
        
        redNum = reds.numChildren;
        if (redNum === 0 || redNum < settings.red.max) {
          console.log('-----tick--------');
          radius = 160
          beginX = Math.floor(Math.random() * stageWidth);
          // toX: -radius or stageWidth + radius
          // toX = beginX < stageWidth / 2 ? stageWidth : 0;

          if (Math.random() < 0.3) {
            toX = beginX < stageWidth / 2 ? stageWidth : 0;
          } else if (Math.random() < 0.7) {
            toX = Math.random() * stageWidth - radius
          }  else if (Math.random()< 1) {
            toX = Math.random() * (stageWidth/2) - radius;
          }
          
          // console.log('----toX-----:', toX)
          // duration: 3s ~ 5s
          duration = Math.floor(Math.random() * 2001) + 2000;

          // 奖品概率
          const n1 = Math.round(Math.random()*100)
          if (!event.paused) {
            console.log('----1--------')
            if ( n1 < 90) {
              if (n1 < 10) {
                red = new createjs.Bitmap('./img/red/red1.png')
              } else if (n1 < 30) {
                red = new createjs.Bitmap('./img/red/red2.png')
              } else if (n1 < 40) {
                red = new createjs.Bitmap('./img/red/red3.png')
              } else if (n1 < 50) {
                red = new createjs.Bitmap('./img/red/red4.png')
              } else if (n1 < 60) {
                red = new createjs.Bitmap('./img/red/red5.png')
              } else  {
                red = new createjs.Bitmap('./img/red/red6.png')
              }
            } else {
              // 小概率波奇豆
              red = new createjs.Bitmap('./img/red/bean.png')
            }
            red.x = beginX;
            red.y = -radius / 2;
            reds.addChild(red);
            createjs.Tween.get(red).to({
              x: toX
            }, duration);
            createjs.Tween.get(red).to({
              y: Math.random() * (stageHeight + 2 * radius)
            }, duration, createjs.Ease.sineOut);
            createjs.Tween.get(red).wait(duration).call(function() {
              return reds.removeChild(red);
            });

            red.addEventListener('click', (evt) => {
              if (!evt.paused) {
                createjs.Ticker.setPaused(true);
                createjs.Ticker.addEventListener('tick', stage);
                console.log('----evt-----:', evt)
                const stageX = evt.stageX
                const stageY = evt.stageY
                const gift = new createjs.Bitmap('./img/red/gift1.png')
                gift.x = stageX
                gift.y = stageY
                reds.removeChild(evt.target)
                reds.addChild(gift)
                createjs.Tween.get(gift).to({
                  x: toX
                }, duration);
                createjs.Tween.get(gift).to({
                  y: Math.random() * (stageHeight + 2 * radius)
                }, duration);
                createjs.Tween.get(gift).wait(duration).call(function() {
                  return reds.removeChild(gift);
                });
                setTimeout(() => {
                  // createjs.Ticker.setPaused(false);
                }, 2000);
                console.log('-----click-----:', evt.target)
              }
            })
          } else {
            console.log('----2--------')
            if (stage && stage.children) {

              var i, l = stage.children.length;

              for (i = 0; i < l; i++) {

              var child = stage.children[i];
              console.log('----child------:', child)
              if ("stop" in child)
                child.stop();
            }
          }
          }
       
        }
      });

      createjs.Ticker.framerate = 60;
      createjs.Ticker.addEventListener('tick', stage);
@lannymcnie
Copy link
Member

I am not clear what this issue/question is. Were you able to solve your issue?

From a glance, it is unclear what evt.paused is: The MouseEvent triggered by the "click" event does not have a paused property (the "tick event is the only one that does). So your !evt.paused will always evaluate to true. Changing the Ticker paused value will not work. Maybe you meant to check event.paused instead?

If not, please post a better description of the steps to show the issue, and a simpler demo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants