Confusing about creating tile system

Im trying to create a tile system like terraria. But i cant make a good algorithm to do it. So i made a list from start to end.

  1. Create tiles in full of screen
  2. Add texture specific tiles
  3. Add rectangle for collision

Does these list of algorithm work for it or do you have better suggestion?

1 Like

I did one once and went down the route of doing it like voxels only in 2d.

Maybe i should create a simple sample.

My approach with tilemaps is to first render tiles without scaling on a RenderTarget, then render this RenderTarget on the screen with a scaling

protected override void Draw(GameTime gameTime)
             int pixelSize = 4;
             RenderTarget _pixelRT = new RenderTarget2D(GraphicsDevice, GraphicsDevice.DisplayMode.Width / pixelSize, GraphicsDevice.DisplayMode.Height / pixelSize); 
             //I recommend creating only one RenderTarget in your Initialize() method instead of doing this

             _spriteBatch.Begin(blendState: BlendState.NonPremultiplied, samplerState: SamplerState.PointClamp);
             foreach (Tile tile in _tiles) {
                         tile.Draw(); //Use your own system for this


             GraphicsDevice.SetRenderTarget(null); //Render on screen
             _spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp);
             _spriteBatch.Draw(_mainRT, new Rectangle(0, 0, pixelSize * _pixelRT.Width, pixelSize * _pixelRT.Height), Color.White);

Hope it’ll help, your post isn’t very clear