【已解决】cleanAllItem方法里用从0开始遍历会有格子清理不掉

liefeng

1 回复26 浏览

来自课程:简单易懂的2048小游戏开发-Cocos入门教程

老师您好, 我在cleanAllItem方法里用从0开始的遍历不行,会有格子清理不掉。用视频里的方法就行,这是为什么

private cleanItem() {
        let children = this.nodeParent.children;
        for (let i = 0; i < children.length; i++) {
            let tile = children[i].getComponent(Tile);
            if (tile) {
                this.nodeParent.removeChild(children[i]);
            }
        }
    }

 

全部回复(1)

  • liefeng 楼主 1 楼

    明白了,因为children后面的节点一直在减小,从0开始的话不能完全遍历

发表回复

登录后可以回复