diff --git a/94xi7aitax.js b/94xi7aitax.js index 258086a..4824c9e 100644 --- a/94xi7aitax.js +++ b/94xi7aitax.js @@ -16,10 +16,17 @@ if (!this.initialized) { this.speed = 15; + this.clouds = []; + this.spawnCloud = function() { + + var cloud = this.cloud.clone(); + this.cloud.position.x = -155; this.cloud.position.z = (Math.random() * 10) - 5; this.cloud.updateInstance('position'); + + this.clouds.push(cloud); } this.initialized = true; @@ -27,8 +34,27 @@ if (!this.initialized) { var diff = data.delta * this.speed; -this.cloud.position.x += diff; -this.cloud.updateInstance('position'); +var deadClouds = this.clouds.reduce( + function(result, cloud) { + cloud.position.x += diff; + cloud.updateInstance('position'); + + if (cloud.position.x > 50) { + result.push(cloud); + } + + return result; + }, + [] +); + +deadClouds.map( + function(deadCloud) { + deadCloud.geometry = null; + deadCloud.materials = null; + deadCloud.remove(); + } +) this.sections.map( function(section) {