Posted: 17th Jun 2007 18:47
Im Currently working on a 2D top view RTS Game. Im using Sprites for my Map tiles. However when I Set my map to be more than 40 Tiles in length and width it slows down too much. It only achieves 5-10 FPS.
Im using 100*100 px Tiles and have tried using smaller Tiles but it doesn't seem to help. My program isnt rendering all the tiles only the tiles on the screen+100px outside of the screen. Is this just my bad coding or is DarkBasic too slow to render all my tiles at once. I have an AMD 3200+, 6600 geforce card and 1 Gig of ram.

I have attached a copy of my game. If anyone could take a look at my code or tell me why its so slow it would be very much appreciated. To get to the Map you need to press. Create Map, then press New Map.
Posted: 17th Jun 2007 19:36

For Down=1 to MAPSIZE
For Across=1 to MAPSIZE

I think this the problem, you have 1600 iterations. You should find on which tile is the camera and use this value in your for-next loops.

+ Code Snippet
   for Down = camTileY to camTileX+12
      for Across = camTileY to camTileY+8
Posted: 17th Jun 2007 20:17
I think I see what you mean but how would I find weather my tiles are being viewed by the camera without looping through every single tile to check weather they are within the view of the camera or not.

The only way I can think of is to group my map tiles into bigger tiles
Like one screen in size and if that Group Tile Is being viewed by the camera then check If each map tile in that Group is being viewed by the camera then render it. Would this method work?
Posted: 17th Jun 2007 22:14
@ WindowsKiller Yep you were right. I Quickly wrote something to test
your suggestion of using Paste Image(Ive attached It). I used sprites because I thought they would be quicker than using Paste Image. Obviously I was wrong. I can have a mapsize of 200 by 200 while having 100 fps.
Posted: 18th Jun 2007 19:29
Paste image is good but ive never found a way to detect collision between pasted images and sprites, although if its for a background then it shouldnt really matter
Posted: 19th Jun 2007 3:32
Check out my tutorial on 2D tile maps.
Technically, the overall size of your map should not affect the speed at all since you should only be drawing what fits on the screen anyway.

http://zimnox.com/?page=dbTutorials
Posted: 19th Jun 2007 18:42
Will give it a look Phalelax. Surely the speed must be reduced with the increase of the amount of tiles you want. The more tiles there are the more you have to loop through even though you aren't rendering them all. Ill edit this post once I have had a read.
Posted: 19th Jun 2007 18:56
You can have thousands of tiles, but you don't need the same number of sprites. You need a dynamic sprite handling/creation system.

And you don't have to iterate through all of the grids every time. You can mathematically iterate only through cells that surround a player. You can create a system that will let you specify a cell padding to the character's cell and iterate only through those, placing the sprite you need at that location. Efficiency is key with a project like this. Games like this often die because the creator can't manage it, but it isn't hard.
Posted: 19th Jun 2007 19:22
I'm Half way through reading Phaelax tutorial and yes I see what you are saying Cash and Phaelax. I don't know why I didn't think of doing it this way to start with. It just makes common sense.

Find the top left position of the viewport in terms of tiles 3 down 3 across for example then from there scroll through only the tiles across and down that your viewport can see.

The way I was doing it was scroll through every tile on the map. Check if it was being viewed by the viewport. If it was paste it to the screen. Much more slow and it kept on growing exponentially slower as the map got bigger.

BTW: Great tutorials Phaelax, I'm going to read through your other tutorials once I get a chance.