SFML - Sprites vs Vertex Array

Started by
1 comment, last by archanian 11 years, 5 months ago
I've implemented a tile-based RTS-style scrolling map with SFML (.NET binding), and would like to get some opinions on two options I can see.

Currently what I am doing is keeping a large collection of Sprites for the map, and each tile stores its terran type and index into the sprite collection. The sprites are stored in a Dictionary<TileType, Sprite[]>, where the keys are the various tile types (enum: Grass, Forest, Ocean, Desert etc ...), and against each key I store an array of all the sprites for that terrain type.

I have a custom camera object which tracks the in-view area, and can be scrolled around the map. Each render call, I get the tiles that are in view according to the camera, and simply loop through them all, find the appropriate sprite in the collection, set its position and draw the sprite.

This works fine, and I get a solid frame rate (80-100 FPS) with 1200+ tiles on screen and several layers on top with complex alpha blending for transitions etc.

The second option I can see (which I have read a bit about) is to store the map data in vertex arrays, and to use the built-in SFML View object to handle scrolling. I'm not too sure how different this method would be, it seems to be pretty much the same approach with slightly different data structures.

I'm still a bit of a beginner with SFML, and most of my previous work has been with SDL Surfaces which are pretty much the same as the Sprite approach I have taken with SFML. Any thoughts, opinions or advice on this is welcome :)
Advertisement
I can't comment on the SFML part of this question.

However, I'd like to say that if it isn't broken, don't fix it.

It seems to me that your current solution is running fine. I'd say stick to your current solution and focus on the next pieces of your project. Don't worry about the 'alternative solution' unless the way you're currently doing things actually ends up becoming a problem (and verify that the sprite approach is the problem with profiling!)

If you're approaching this purely out of curiosity though then, by all means, dig into it.

Good luck on the project! :)
Thanks for the feedback. I totally agree with you - and it definitely isn't broken, I was just being curious ...
I've only recently started using SFML after several years with SDL, so my mind is racing with lots of questions :)
Sometimes this can be my downfall - instead of questioning things perhaps I should just forge ahead and question it when I have a problem.

This topic is closed to new replies.

Advertisement