在for循环中加入延时函数setTimeout,因加入延时导致,i总是取得超出边界的值
for(var i=0;i<len;i++){ setTimeout(function () { cc.warn("lrcs ",self.Lrcs[i]); },i*(this.singsDuration/(len-1))) }
解决方案:
for(var i=0;i<len;i++){ this.creatFunction(i,i*(this.singsDuration/len)); } }, creatFunction:function (i,time) { var self=this; setTimeout(function () { self.Lrcs[i].getComponent(cc.Animation).play("WTBAni"); },time*1000) },