Jump to content

  • Log In with Google      Sign In   
  • Create Account


SFML - Sprites vs Vertex Array


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 archanian   Members   -  Reputation: 247

Like
0Likes
Like

Posted 11 November 2012 - 10:43 PM

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 :)

Sponsor:

#2 caldiar   Members   -  Reputation: 702

Like
0Likes
Like

Posted 12 November 2012 - 04:38 PM

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! :)

#3 archanian   Members   -  Reputation: 247

Like
0Likes
Like

Posted 12 November 2012 - 05:06 PM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS