diff --git a/src/main.js b/src/main.js index 41579fc..778449f 100644 --- a/src/main.js +++ b/src/main.js @@ -529,7 +529,7 @@ clearedByColor[key] = (clearedByColor[key] || 0) + 1; } }); - removeBlob(id); + spawnSystem.removeBlob(id); }); // Remove cleared balls from tracking list. for (let i = balls.length - 1; i >= 0; i -= 1) { diff --git a/src/spawn.js b/src/spawn.js index a3fe062..6c894e5 100644 --- a/src/spawn.js +++ b/src/spawn.js @@ -452,6 +452,21 @@ }); }; + const removeBlob = (blobId) => { + if (!blobId) return; + const constraints = blobConstraints.get(blobId) || []; + constraints.forEach((c) => World.remove(world, c)); + blobConstraints.delete(blobId); + for (let i = balls.length - 1; i >= 0; i -= 1) { + const ball = balls[i]; + if (ball.plugin?.blobId === blobId) { + cleanupBall(ball); + World.remove(world, ball); + balls.splice(i, 1); + } + } + }; + const resetSpawnState = () => { spawnCount = 0; }; @@ -465,6 +480,7 @@ updateBallRadius, computeBallRadius, cleanupBall, + removeBlob, resetSpawnState, }; };