Click here to Skip to main content
12,241,861 members (52,633 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# XNA3.0
Hello everyone!

I am using XNA to develope a game of mine. It's similar to Terraria and Minecraft so I'd just call it a 2D voxel engine. And basically, I just created a Chunk System that works fine. The only problem I have so far is drawing the view. When I draw the view, I draw block by block, now obviously that will give you a wierd grid effect. I got a picture below to give you an understanding of what I currently have and what I want to have.


Basically, I am currently drawing the blocks in a view snapped to the blocks, which I do by using the middle chunk(4), I could also get a block by doing ThePlayer.GetBlock, in that way I can get a block in the loaded chunks next to it. So even though I have a method that could help me out a lot I am still unsure on how to make the view work with multiple blocks, anyways here is the code:

public void DrawWorld()
            Chunk Chunk = ThePlayer.LoadedChunks[4];
            foreach (Block Block in Chunk._Blocks)
                // -- Color.
                Texture2D toDraw = null;
                // -- Get the Right Block.
                switch (Block.BlockID)
                    case ID.BLOCK_AIR:
                        toDraw = BlockAir;
                    case ID.BLOCK_DIRT:
                        toDraw = BlockDirt;
                    case ID.BLOCK_GRASS:
                        toDraw = BlockGrass;
                    case ID.BLOCK_SAND:
                        toDraw = BlockSand;
                    case ID.BLOCK_STONE:
                        toDraw = BlockStone;
                    case ID.BLOCK_COBBLESTONE:
                        toDraw = BlockCobblestone;
                    case ID.BLOCK_BRICK:
                        toDraw = BlockBrick;
                    case ID.BLOCK_WOODPLANK:
                        toDraw = BlockPlank;
                Rectangle _Rec = new Rectangle(Block.X * ID.BlockSize - ThePlayer.BlockX * ID.BlockSize, Block.Y * ID.BlockSize - ThePlayer.BlockY * ID.BlockSize, ID.BlockSize, ID.BlockSize);
                spriteBatch.Draw(toDraw, _Rec, Color.White);
                spriteBatch.DrawString(FontTerrasylum, "Pixel: " + ThePlayer.PixelX + " " + ThePlayer.PixelY, new Vector2(0, 0), Color.White);
                spriteBatch.DrawString(FontTerrasylum, "Block: " + ThePlayer.BlockX + " " + ThePlayer.BlockY, new Vector2(0, 32), Color.White);
                spriteBatch.DrawString(FontTerrasylum, "Chunk: " + ThePlayer.ChunkX + " " + ThePlayer.ChunkY, new Vector2(0, 64), Color.White);

Also; There are some important variables:

- X
- Y
- Blocks
- X
- Y


Posted 8-Jan-13 2:33am
Yvar Birx2.4K
Edited 8-Jan-13 2:35am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.160426.1 | Last Updated 8 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100