for (let index = 0; index < this.content.children.length; index++) {
let userNode = this.content.children[index];
this.enemyPool.put(userNode); //存回对象池
console.log(index);
}
result:50
只有50个?why?
for (let index = 0; index < this.content.children.length; index++) {
let userNode = this.content.children[index];
this.enemyPool.put(userNode); //存回对象池
console.log(index);
}
result:50
只有50个?why?
第一次:1,3,5,7,9 回收。。。
存回对象池后,this.content.children就变了,应该在for之前取出长度,然后一直把第一个放进去就可以
[…this.content.children].forEach((node)=>{
this.enemyPool.put(node);
})
for (let index = this.content.children.length; index >= 0 ; index–) {
let userNode = this.content.children[index];
this.enemyPool.put(userNode); //存回对象池
console.log(index);
}