hello guys!! I found that group is so convenience to create a game object pool!!
But when I call group.Kill (or group.KillAndHide) function, the group will stop create another object
When I called Kill(), removeCallback was not be called too (Same in this example)
Was my code have some problem?
let CloudPool = this.add.group({
classType: Phaser.GameObjects.Image,
maxSize: -1,
createCallback: (object) => {
console.log("Create")
object.setTexture(Texutre, 'darkcloud-' + (Math.round(Math.random() * 1) + 1))
object.x = CenterX * 2 + (Math.random() * CenterX * 2) + object.width
object.y = Math.random() * (CenterY * 2)
object.speed = 1
},
removeCallback: (object) => {
console.log('Removed', object.name); // Not work any time
object.setActive(false)
object.x = -object.width / 2
object.speed = 0
object.update = () => { }
}
})
this.UpdatePool = () => {
CloudPool.children.iterate(object => {
object.x -= object.speed
if (object.x < -object.width / 2) {
CloudPool.kill(object) // When kill it, the Get() function will not work
}
})
}
this.tweens.addCounter({
loop: -1,
repeat: -1,
repeatDelay: 0,
duration: 10,
onRepeat: () => {
CloudPool.get()
}
})
}
update() {
this.UpdatePool()
}
Thanks a lot !!!
** Update **
I solve it with group.remove(child [, removeFromScene] [, destroyChild]) !!!