diff --git a/assets/Scripts/Game/Background/Background.ts b/assets/Scripts/Game/Background/Background.ts index 878b442..59c168f 100644 --- a/assets/Scripts/Game/Background/Background.ts +++ b/assets/Scripts/Game/Background/Background.ts @@ -60,14 +60,15 @@ export class Background extends Component { } } else if (this.playerGridPosX < playerGridPosX) { // move the first column to the right + const columnIndex = 0; for (let i = 0; i < this.rows; i++) { - const instancedNode = this.instancedBackgrounds[i][0]; + const instancedNode = this.instancedBackgrounds[i][columnIndex]; const newPosition: Vec3 = instancedNode.worldPosition; newPosition.x += this.columns * this.nodeSize; instancedNode.setWorldPosition(newPosition); - this.instancedBackgrounds[i].splice(0, 1); + this.instancedBackgrounds[i].splice(columnIndex, 1); this.instancedBackgrounds[i].push(instancedNode); } } @@ -95,9 +96,10 @@ export class Background extends Component { this.instancedBackgrounds.unshift(nodesInRow); } else if (this.playerGridPosY < playerGridPosY) { // move the first row up + const rowIndex = 0; const nodesInRow: Node[] = []; for (let i = 0; i < this.columns; i++) { - const instancedNode = this.instancedBackgrounds[0][i]; + const instancedNode = this.instancedBackgrounds[rowIndex][i]; const newPosition: Vec3 = instancedNode.worldPosition; newPosition.y += this.rows * this.nodeSize; @@ -105,7 +107,7 @@ export class Background extends Component { nodesInRow.push(instancedNode); } - this.instancedBackgrounds.splice(0, 1); + this.instancedBackgrounds.splice(rowIndex, 1); this.instancedBackgrounds.push(nodesInRow); }