This question is SOLVED
Using Unity 4.0 (free), C#, Windows 7 pro;
Currently, I am trying to make a game system for 2D side-scroller. If you know the game called Terraria, you might have a better idea of what I’m trying to do here.
This is a screen shot from Terraria. In this game, the player can dig, and place a block (or tile whatever you want to call it). Like Minecraft, but in very flat 2D world.
The game has a world around 4000 wide x 1000 high blocks. (a small world that is)
So my goal is to create a 2D side scroller with possibly 4 million blocks.
Anyhow, I’ve created a prototype using a free 2D framework called Orthello, which comes with a sprite class called OTSprite. It worked until the world exceeded 100x100 blocks.
The structure was very simple and inadequate. I simply created an empty gameObject and added the blocks. The framework handled the drawing calls and calls were reduced to 1 (other calls from blocks within the visible area were batched).
Above image is my prototype. I’ve made a noise based 2D terrain data generator so the ground is in kind of a weird shoe looking shape. In this picture, there are 881 blocks and it is working fine, but far far from my goals. So if you are planning on doing a similar idea like me, don’t. It won’t work.
Now, I’d like to talk about a solution that actually works. One idea is that I will build a 2D version of what is known as a voxel engine. Since the word voxel refers to a 3D box, I might call it a “Planel Engine”, because we are adding bunch of planes instead of boxes. I know, there’s no such word.
So far, thanks forum members who answered to my previous question. I hope this cleared some confusion…
So now my project has shifted from having bunch o’ orthello sprites to procedural mesh creation.
I’ve read some websites and learned the basic of the mesh, vertices, triangles, UVs and I’ve made this image below so far. (no primitives used. code only)
This is 64 planes by 64 planes (or 4096 blocks), which is my hypothetical chunk size. (if not too large?? Not based on anything, so I’m open to any suggestions.)
This is my 3rd rev.
I’ve found some solution to my previous questions, and my world is getting closer to 4 mil tiles.
Here is 1 chunk of mesh drawn with textures.
In a loop where I determine the block type for my game’s block coordinate, I set the UVs for each plane. I’m using a text texture to display just a few patterns(in the picture, I’m using transparent block, and a red block).
First I had an error where my transparent PNG texture became all white, but I fixed that with photoshop, adding an alpha layer. It says PNG24 instead of PNG32, so it is kind of confusing.
Now, to turn ON/OFF the block, I just need to find a block in my game block coordinates, and change preset UVs from A to B.
Regarding the chunk size. 1 mesh can ONLY HOLD, up to 65000 vertices. I got this error.
Mesh.vertices is too large. A mesh may not have more than 65000 vertices.
So, from this error, my chunk is now determined as 100x100 blocks. ish. This may change.
Now, my last question is, how should I make an entire world, instead of a chunk.
And I think it is already given to me by @Bunnybomb7670 !
Thank you guys, I really appreciate all the comments and answers.
Rev4.
My code was getting quite messy, so I was re-factoring my code. And I added a different solution to my mesh creation regarding the empty planes.
My first approach was to … Set a transparent texture UVs for empty space. My second approach is not adding the vertices/UVs/triangles the whole set, but add vertices count up, so it can be re-filled later on (hopefully).
This is the picture from my second approach. No mesh in the transparent area.
Now re-factoring is done, I can move on to chunks… will post soon.
** Rev 5 **
Took me little longer than I expected… I implemented the chunks. Now they are all good to go!
I also implemented collision for character movement test. Now each tile(or block) is ready to be walked. Thanks guys!!