Quantcast
Channel: Cocos中文社区 - 最新主题
Viewing all articles
Browse latest Browse all 88737

ToggleParticle改写以后出现的一个问题

$
0
0

@704436993 写道:

我在ToggleParticle里面加了一个progressBar,想实现当进度条满的时候,点击触发粒子的发射,粒子发射后进度条清零重新填满。功能实现了,但是里面有个关于this作用域的问题很奇怪,希望哪位大神可以解答下。

下面是代码:
cc.Class({
extends: cc.Component,

properties: {
    particle: {
        default: null,
        type: cc.Node
    },
    
    progressBar:{
        default:null,
        type:cc.ProgressBar
    },
 
   speed:5,
},

onLoad: function () {
this.progressBar.progress = 0;
this.ready = false;
this.setInputControl();
},

setInputControl: function(progressBar) {
_ var self = this;_
_ this.node.on('mousedown', function(){_
_ console.log('mousedown');_
_ console.log(self);_
_ console.log(this);_
_ self.toggleParticlePlay();_
_ self.progressBar.progress=0;_
_ }.bind(this)); _
_ },_

toggleParticlePlay: function() {
var myParticle = this.particle.getComponent(cc.ParticleSystem);
if (myParticle.isFull()) { // check if particle has fully plaed
myParticle.stopSystem(); // stop particle system
} else {
myParticle.resetSystem(); // restart particle system
}
},

update: function (dt) {
    this._updateProgressFull(this.progressBar,dt);
    if (this.ready) {
        this.setInputControl(this.progressBar);
        this.ready = false;
    }
},

_updateProgressFull: function (progressBar,dt) {
  var progress = progressBar.progress;
  if(progress<1.0 && !this.ready) {
      progress +=dt*this.speed;
      progressBar.progress = progress;
     } else if (progress>=1) {
         progressBar.progress=1;
         this.ready=true;
     }
},

});

帖子: 4

参与者: 1

阅读整个主题


Viewing all articles
Browse latest Browse all 88737

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>