🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Game world rendering

Started by
6 comments, last by heh65532 3 years, 10 months ago

Hi

I have a question about game world rendering. What is the best way to render background graphics such as grass and trees in 2D for your game?

Normally I would use array of tiles where every grass tile and tree are but I have big game world and for that this seems like too memory hungry solution

So what I need is nearly infinite game world rendering. the game I'm making is completely tileless and the game objects move using vectors

Also I need to render rivers

Some example pictures of what kind of game world I mean: maps

thanks

Advertisement

You don't need to render the whole game world, only the part that is on the screen at the time. You can also reuse your tiles, so you only need one grass tile in memory to render all your grass tiles.

Here's a great article on the subject, it even uses trees and tiles as an example ?
https://gameprogrammingpatterns.com/flyweight.html

I'm not sure what you mean by “tileless world” and vector movement, but a silimar thing applies: you don't need the whole map in memory at all times, only that part that you are using at the moment.

@1024 I have towns and castle objects stored in array where each object has it's own x,y coordinate so that I don't have a tile array. I was thinking of doing same for hill,tree,river graphics so that they too have x,y coordinate and again no tile array just object list

Is this good idea?

I guess that can work, depends what you want to do with them. Rivers are usually long, so if you want to interact with them, just having one x,y coordinate probably won't work.

The rivers are just background detail

Having one big array of objects is probably not a good idea, as you would have to go through the entire array every time you render. This is going to slow down things a lot once you go over a million objects or so. By contrast, a tile map with millions or even billions of tiles isn't going to be a problem because you only need to look at the parts of the map that you want to render.

Look up spatial partitioning (e.g. quad-trees) for a possible solution to this. My preferred technique is to divide the world into a grid of “cells”, where each cell has its own array of objects. Now you only need to render the objects in the cells on the screen, which is much faster than iterating through an array with millions of entries.

I'm not good with high tech articles partly due to language barrier but I implemented chunk system where each chunk contains bunch of tree locations and I put these chunks in [x][y] array. And in the renderer I pick the center chunk and the sides and render those. So that's 9 chunks being rendered at a time. Faster than all trees being looped at once

This topic is closed to new replies.

Advertisement