• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Mellkor

2D tilemaps "Chunk Theory".

9 posts in this topic

Hello!

 

I'm looking to get as much theory as possible on this subject, I have a hobby project i'm working on: a 2D orthographic game which i have used the standard tile grid array technique to render in XNA. But would like to implement dynamic loading of groups of tiles (chunks) so i can implement larger worlds then a standard grid.

 

The part of the theory i most understand is when the camera, or object gets close to the edge of a chunk the new one is loaded in the direction the camera is traveling and the chunk behind is unloaded. I guess the theory is to have an array that tracks chunks, then another array inside the chunk to track tiles?

 

Things I don't understand:

  • Loading an adjacent chunk that "lines up" with the old one.
  • Best way to "signal" a new chunk should be loaded.
  • General Implementation details

 

I would like to heavy research this topic as i want it to be a center point of any other 2d games i make in the future.

So i welcome any and all recommended:

  • Books
  • Tutorials
  • Videos

And of course code snippets and comments would be very valuable to me. (most proficient with XNA)

 

Thanks.

 

Edit: (Also had another question on general tile maps, should i ask here or start a new thread)?

Edited by Mellkor
0

Share this post


Link to post
Share on other sites

This is my very simple attempt at drawing a single chunk, Its probably horribly inefficient and "incorrect" lol

public class Game1 : Game
    {
        //Chunksize
        int width = 10;
        int height = 10;

        //tilesize
        int tSize = 64;

        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        public static Texture2D texture;

        //Chunks
        chunk[] ChunkArray = new chunk[5];

        //Tile
        public class tile
        {
            public Texture2D texture;
        }

        //chunk
        public class chunk
        {
            public tile[,] tiles;

            public chunk()
            {
                this.tiles = new tile[5, 5];
                BuildChunk();
            }

            public void BuildChunk()
            {
                for (int x = 0; x < 5; x++)
                {
                    for (int y = 0; y < 5; y++)
                    {
                        this.tiles[x, y] = new tile();
                        this.tiles[x, y].texture = Game1.texture;
                    }
                }

            }

        }
        private void addChunkToArray()
        {
            ChunkArray[0] = new chunk();
        }

        public Game1()
            : base()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }


        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();
        }


        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            texture = Content.Load<Texture2D>("tile.png");
            addChunkToArray();
            // TODO: use this.Content to load your game content here
        }

        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            spriteBatch.Begin();

            //foreach (var chunk in ChunkArray)
            for (int ci = 0; ci < ChunkArray.Length; ci++)
            {
                {
                    if (ChunkArray[ci] != null)
                    {
                        foreach (var tile in ChunkArray[ci].tiles)
                        {
                            for (int y = 0; y < height; y++)
                            {
                                for (int x = 0; x < width; x++)
                                {
                                    spriteBatch.Draw(tile.texture, new Rectangle(x * 64, y * 64, tSize, tSize), Color.White);
                                }
                            }
                        }
                    }
                }
                spriteBatch.End();
                base.Draw(gameTime);
            }
        }
    }
}

 My next goal was to set up another chunk to the right of that one using the array, but it seems from your post that i should pretty much reevaluate the whole theory?

0

Share this post


Link to post
Share on other sites

Assuming the map can expand in four directions, you might have a grid of 9 chunks, much like a Tic-Tac-Toe board, loaded into memory at once (if you are only moving in one direction, vertically or horizontally, then 3 or 5 would be a better  number). The chunk in which the player currently resides is always at the center. When the player crosses the boundary into another chunk, then you would unload one column or row and load a new one depending on the direction the player moved.

For example, say the player moves north into the chunk directly above the center one. Now, you unload the entire bottom row (three chunks). The center row now becomes the bottom row, the top row now becomes the center row, and you load three new chunks to fill in the top row. If diagonal movement is disallowed, you could simplify it to 5 chunks - the middle, N, S, E and W. You're still loading and unloading the same number of chunks, just in a different pattern. But I'd still go with 9 myself.

You'll want a decent chunk size for this, though. If the chunks are too small, you'll be loading more frequently unless you adapt the algorithm a bit.
 

1

Share this post


Link to post
Share on other sites

Assuming the map can expand in four directions, you might have a grid of 9 chunks, much like a Tic-Tac-Toe board, loaded into memory at once (if you are only moving in one direction, vertically or horizontally, then 3 or 5 would be a better  number). The chunk in which the player currently resides is always at the center. When the player crosses the boundary into another chunk, then you would unload one column or row and load a new one depending on the direction the player moved.

For example, say the player moves north into the chunk directly above the center one. Now, you unload the entire bottom row (three chunks). The center row now becomes the bottom row, the top row now becomes the center row, and you load three new chunks to fill in the top row. If diagonal movement is disallowed, you could simplify it to 5 chunks - the middle, N, S, E and W. You're still loading and unloading the same number of chunks, just in a different pattern. But I'd still go with 9 myself.

You'll want a decent chunk size for this, though. If the chunks are too small, you'll be loading more frequently unless you adapt the algorithm a bit.
 

 

Yes, I understand that in theory, and that's what i'm trying to accomplish but its the implementation theory that's my problem.

 

If I have a chunk that is 50x50 tiles big, The player/camera gets to local tile 30,0 and wants to load the next chunk(next set of 50x50 tiles), How do i know where to start drawing the next chunk?

Edited by Mellkor
0

Share this post


Link to post
Share on other sites

Hi Mellkor smile.png

A similar question popped up on the Microsoft XNA forums a while back, and I posted some graphics to visualize the theory and a code sample with class diagram.

(scroll down to "I found some time yesterday, and coded a framework for making infinite worlds.")

 

I hope it will prove useful to you smile.png

 

Kind regards - Jakob

 

Thanks mate! ill have take a look over the drawings and code.

0

Share this post


Link to post
Share on other sites

 ( I am working on a similar problem in Java )

From what I am reading - small "chunk" groups need to be saved as a separate map files, and loaded into memory off screen to reduce "lag".

However the more I think about it - wouldn't constantly opining and closing files cause system strain ?

 

 How the hay does MineCraft do it ?

Edited by Shippou
0

Share this post


Link to post
Share on other sites
Hi Shippou You could fiddle a bit with the chunk sizes, to ensure that you would only read/dump files from and to disk every so often. If your maps are pretty simple, the amount of data in memory shouldn't be a problem. To my knowledge this is the same way Minecraft does it. You could also cache a bigger amount of chunks, say two concentric circles worth around the one the player is currently in. I can't see this becoming a problem on modern computers. Try the sample that's for download on my Blog - I haven't experienced any problems, and the chunks there are very small, to illustrate the concept. If you make 255x255 chunks you would load a lot less and the files would still be fast to read and not too much of a strain on memory. Kind regards - Jakob
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0