[CENTER]TL;DR version: how do I add more values to the 0th row of an array?
[If that’s too vague, read on.]
[/CENTER]
Hello again! I’m back, with another issue.
What I’m trying to do currently is make a tilemap engine. I have an multidimensional array that is sifted through when the program begins that determines what type of tile is added to the stage which was then put in its appropriate place. These tiles scroll when the player moves.
Now, the problem is, I expect to make huge maps. Putting a large amount of children (tiles) on the stage makes the program incredibly laggy, so to fix this I created another multidimensional array that held the values of the tiles that are currently in the field of vision of the player.
the values in the new array shifts and moves along with the player, gets the children that will be left behind and deletes them. To keep things short, the player would not notice the addition and removal of the tiles, because the tiles are added at the position where the player* is currently moving* and the tiles that are removed are removed where the player is moving away from.
I’ve already made it to where the player can move left and right without any issues.
The issue I am having lies with moving up and down. The addition and removal of tiles follows a very strict process:
- shift the array that holds tiles in the player’s range of vision so that new tile values can be added.
- add children (tiles), assign their names, add the name to the appropriate place in the array and move the child (tile) to the appropriate place on the stage.
- Delete the tiles left behind.
- Remove the names of the children that were deleted from the array.
To move up, I would have to unshift the array (so that all the rows move down one), add the names of the new children(tiles) that will appear directly above the range of view, then delete the children that are named in the last row of the array and pop the last value in the array (which, since this is a multidimensional array, is not one value, but the entire last row of children names). The problem is, after I unshift the array and add a new row with only a single value in it, I can’t add more values into the row!
(the name of the array that holds the names of the children in the player’s range of view is containmentUnit.)
I have tried these,
containmentUnit[0].push("test");
containmentUnit[0].splice(0, 0, "test");
but it always comes out the same way-- with an error message that reads:
TypeError: Error #1006: value is not a function.
at storage/update()
So, does anybody know how I could add some values to that first row? All help is appreciated!!! :trout: