-1

Im working on a small project in Monogame.

I have a small annoyance though. Currently im loading textures etc on start of the game, Only once.

Im then drawing a map from a CSV file, So currently i'm drawing a map of 3600 tiles, Each tile sizing at 32x32.

To access the tiles the game has to read through an array of Texture2D's (1024 tiles inside of the array). The thing is its lagging quiet a bit.. It can easily handle 100 tile map, But on this bigger one it just lags alot?

Anyone know why this may be happening? If any code is needed, Please do let me know and ill edit my post.

John Conde
  • 217,595
  • 99
  • 455
  • 496
Taylor
  • 1
  • What about only providing a reasonable range of tiles? It's rather pointless to render tiles that cannot be seen... – Willem Van Onsem Apr 13 '15 at 00:07
  • @CommuSoft Im fairly new to C# So i currently have no idea how to do that, Yet. – Taylor Apr 13 '15 at 00:11
  • You need to figure out what makes your code slow and than clarify your question with code that causes slowness. Note that simple fact that rendering 10x tiles makes your code slow is not enough - clearly at some point rendering more objects will overwhelm one or more components of your system. Sprinkle your code with Stopwatch'es and measure (not user if you have access to profiler, but if you can get one it would be much better). – Alexei Levenkov Apr 13 '15 at 00:49

1 Answers1

0

This sounds to me like an optimization issue. Surely you don't need to draw all 3,600 map tiles straight away - just the tiles that the player can see? When they are moving around the map then you can have an event to load more tiles in and destroy the tiles that have gone out of view.

So you need to add a way to keep track of what the player can see and only load tiles within this boundary.

Think about Minecraft. If it tried to load billions of blocks into memory at runtime then it would fall over very quickly. Instead it only renders the blocks the player can see.

markp3rry
  • 724
  • 10
  • 26