named index 0

This commit is contained in:
Martin 2022-12-13 10:24:17 +01:00
parent 91ad84e338
commit e626d493d2

View File

@ -60,14 +60,15 @@ export class Background extends Component {
} }
} else if (this.playerGridPosX < playerGridPosX) { } else if (this.playerGridPosX < playerGridPosX) {
// move the first column to the right // move the first column to the right
const columnIndex = 0;
for (let i = 0; i < this.rows; i++) { 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; const newPosition: Vec3 = instancedNode.worldPosition;
newPosition.x += this.columns * this.nodeSize; newPosition.x += this.columns * this.nodeSize;
instancedNode.setWorldPosition(newPosition); instancedNode.setWorldPosition(newPosition);
this.instancedBackgrounds[i].splice(0, 1); this.instancedBackgrounds[i].splice(columnIndex, 1);
this.instancedBackgrounds[i].push(instancedNode); this.instancedBackgrounds[i].push(instancedNode);
} }
} }
@ -95,9 +96,10 @@ export class Background extends Component {
this.instancedBackgrounds.unshift(nodesInRow); this.instancedBackgrounds.unshift(nodesInRow);
} else if (this.playerGridPosY < playerGridPosY) { } else if (this.playerGridPosY < playerGridPosY) {
// move the first row up // move the first row up
const rowIndex = 0;
const nodesInRow: Node[] = []; const nodesInRow: Node[] = [];
for (let i = 0; i < this.columns; i++) { 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; const newPosition: Vec3 = instancedNode.worldPosition;
newPosition.y += this.rows * this.nodeSize; newPosition.y += this.rows * this.nodeSize;
@ -105,7 +107,7 @@ export class Background extends Component {
nodesInRow.push(instancedNode); nodesInRow.push(instancedNode);
} }
this.instancedBackgrounds.splice(0, 1); this.instancedBackgrounds.splice(rowIndex, 1);
this.instancedBackgrounds.push(nodesInRow); this.instancedBackgrounds.push(nodesInRow);
} }