Jump to content
  • Advertisement
Sign in to follow this  

SFML 1.6 Sprite Vectors

This topic is 2002 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I learned that to control multiple sprites on the screen I should put them into a vector, controlling them from a vector and draw them from a vector, I have been looking all over the internet for good example but I just can't find any, I just want a simple and easy explanation on how it works. So if someone could show me through simple code or lead to a place I can learn it I would be very appreciative :)

Share this post

Link to post
Share on other sites
Well a vector in C++ is a dynamic array in the standard library. I hope you got your fundamentals in programming. I don't think there really are any examples that will show you how to use specific case. The best thing I can redirect you to is basic programming tutorials.

Anyway I can at least give it a try to explain :)

Like I said a vector is an array that dynamically expands depending on the need. Let's say we have 5 elements in it and it's size is 5 as well. If we add another object the vector will resize to fit your need. Why you would want a vector to control and render the sprites is because in most cases you don't know how many sprites you will be needing.

Most often you encapsulate the sprites inside another class, let's say an Entity. You have a vector containing all entities in the world. What you would do now is that you iterate over this array and call the update function on the seperate instances in the vector in order to "control" the sprites inside them. You could render them in there as well but most often you want to seperate that out to it's own function or even own abstraction.

A quick example:
[source lang="cpp"]std::vector<Game::Entity> gameEntities;
// More initialization code

// And then on every frame in the mainloop:
for(int index = 0; index < gameEntities.size(); index++)
Also, I recommend that you have a look at SFML 2.0RC instead of using legacy SFML 1.6

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!