用schedule获取循环无法获取最新的坐标值?

使用schedule循环获取最后一个元素的坐标值,然后生成新的元素,但是每次获取的坐标值都是一样的,生成的新元素都叠在一起了

start() {
    var self = this;
      self.schedule(function () {
        var buttons = self.Buttons;
        var colorButton = self.ColorButton;
        //创建彩色按钮
        var newColorButton = cc.instantiate(colorButton.node);   
        newColorButton.parent = buttons;
        console.log("重复")
        newColorButton.setPosition(buttons.children[buttons.children.length-1].x+100, 0)} ,1);//感觉是这句有问题
        
},

update(dt) {
    var self = this;
    var buttons = self.Buttons;
    //删除出界的按钮
    if(buttons.children.length>0){
    var newColorButtonX = buttons.children[0].convertToWorldSpaceAR(cc.v2(0, 0)).x;
    if (newColorButtonX < -100) {
        buttons.children[0].destroy();
        console.log("已删除")
    } else {}
}else{}
},

buttons.children[buttons.children.length-1],不就是newColorButton吗

newColorButton.setPosition(buttons.children[buttons.children.length-1].x+100, 0)
等于newColorButton.x+=100;
你log打出来看看

1赞