- Home /
Generating 2D Level Through Arrays
Hello again,
I'm currently trying to generate a 2D platformer level by using nothing but code, particularly arrays. The plan is to have 1 by 1 blocks line up with each other to create a simple but basic set of platforms.
It's a process that is very similar to programming platformers through Actionscript 3 with CS Flash.
Here's my coding so far. When I run it, nothing is generated with the two arrays inside my var level array. But I need to figure out some way to makes rows and columns of blocks through arrays.
var level:Array = new Array();
var row:Array = new Array();
var brick:GameObject;
function Start()
{
level = [[1,1,1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1,1,1]];
levelParent = GameObject.Find("Level");
for(var i:int = 0; i < level.length; i++)
{
row = level[i];
for(var j:int = 0; j < row.length; j++)
{
if(level[i] == 1)
{
clone = Instantiate(brick, Vector3(i, j, 0), Quaternion.identity);
clone.transform.parent = levelParent.gameObject.transform;
}
}
}
}
Any suggestions? Thanks!
Try to take your code in update function. If not (which is likely) please inform by answering my comment. I will take a deeper look to your code.
Adding it to update would make it generate the level every frame until it crashes..
Try add a size variable add it to position. var size=10; clone = Instantiate(brick, Vector3(i*size, j*size, 0), Quaternion.identity);
Your answer
Follow this Question
Related Questions
Storing level data from a texture file, and drawing at speed. 0 Answers
2D array values are not updating or pointers are using old instance in Javascript (fixed?) 1 Answer
Make a Button For Every String in an Array of Level Names 1 Answer
Add elements to array/list in inspector? 1 Answer
Don't destroy material 0 Answers