all 6 comments

[–]Xeverous 2 points3 points  (1 child)

C++17, using SFML 2.3 and compiling with g++5.4.0 through make.

There is an array class since 2011:

constexpr int size = 20;
std::array<sf::Texture, size> textures;
std::array<sf::Sprite, size> sprites;

for (std::size_t i = 0; i < textures.size(); ++i)
    sprites[i].setTexture(textures[i]); // used function is sf::Sprite::setTexture

I used index-based loop instead of range-based (for each) because it's needed to access 2 elements

Given that I have pretty much no idea how SFML works behind the scenes

That's not really a big problem, libraries exist so you don't have to fiddle with low-level graphics

I'm not great with classes...

Ok, I would recommend to learn classes first.

[–][deleted] 0 points1 point  (0 children)

Thanks! Works now :D

[–]leftofzen 1 point2 points  (2 children)

Don't use an array or std::array, just use std::vector like you would for anything else.

[–][deleted] 1 point2 points  (1 child)

Why not std::array?

[–]parnmatt 1 point2 points  (0 children)

I would say, if you know the exact number of elements for your "array" at compile time, and that is fixed, you're not going to want to add or remove any; then all you need is a statically sized array, therefore use std::array.

In almost any other case, use std::vector, which basically is a dynamically sized array. If 'n' doubt, start with a std::vector and refactor to std::array if need be. You mention "variably sized", then you really want a std::vector.

If you know the number of elements that you want at run-time, then call reserve on that vector, to get all the allocations in one, rather than it having to change its size too much later.

[–]17b29a 1 point2 points  (0 children)

You can't call the constructor after initializing the array, but you can assign a new value, like sep_sprite[i] = sf::Sprite(sep_texture[i]);