Hey I can also make nice listings
- All the answers in here are free and all the time spent to answer in here is taken their responses free time. If you expect a high-quality, book-perfect answer you're way off here. As a tip, appreciate every answer you get, because it's not very common, that people spend evenings just answering questions, which the asking person could find the answer to it on their own, if he just spent some more time researching the tutorials, the documentation, the source and the concepts of C++.
- I was typing on my phone and didn't want to write an complete essay on my touch keyboard. So I apologize that I didn't add tons of examples.
- Although I didn't answer your questions directly, I did tell you the solution to the actual problem, so my answer wasn't just useless or anything. It just wasn't complete.
- I'm aware that ranks and all don't really matter, but it's just very sad to see people join a new forum, totally unaware of their surroundings, what the rules are, how people talk to each other, etc. and the within in the first few posts just show their hate/annoyance towards members that have been around for quite a bit and help quite a few people. I personally try always to be most respectful to anyone when I join a new community. It preserves the atmosphere and you as newbie gain some respect in return.
I gave you enough of an example to see exactly what was needed. It was enough or you wouldn't have been able to point out the issue. I made a subjective decision on that, and it was the right decision. Don't ask for a complete code listing when I gave you enough. Ask for a complete code listing when I don't.
I never requested a full listing for your current code, I simply said "Also for further post", which obviously doesn't include this one. I gave you this advice since I saw that you're new to this forum and most of the new comers don't even think about providing complete examples and me having to answer in every other post "please provide a complete and minimal example that reproduces the error" gets quite annoying too. Prevention is better than reaction.
Besides that, I can request whatever I want, like: "I want a chocolate cake from you."
But you're not forced to follow my requests. (It's called freedom of speech and freedom of decisions.)
1. Tell me my code is using bad practices for SFML, but choose not to link me to anything I can actually learn from, and
- Don't pass the window as pointer, pass it as reference. Also instead of passing by value (e.g. std::string), pass them as const reference.
- Don't use arrays, specially if you have to pass it around. If you (for some reason) don't want to use std::vector then at least use std::array (TR1/C++11). The problem with a pure array is, that you never really know it's size and thus you'll have to use many hard coded numbers or other not so nice hacks.
- Don't create a additional sprite object just to initialize it, if you're only purpose is to copy that object to another place later on. E.g. just use setTexture() to set the texture instead of sp(bt).
But then again this is all some mock-up code, so maybe you usually do follow all of these things.
2. Failed to answer the question I specifically asked for. Which is, what is the interaction between images, textures, and sprites.
sf::Image is a representation of an image and lives on the RAM.
sf::Texture is a representation of an image and lives on the memory of the GPU.
To get a sf::Texture things get internally loaded as a sf::Image and then copied to the GPU's memory. This operation is slow, thus one shouldn't have to copy stuff from the RAM to the GPU memory too much.
sf::Sprite holds a reference to a sf::Texture. If the reference is dead, i.e. the sf::Texture went out of scope or no texture has been set, then you'll get a rectangle filled with the color defined for the sprite.
To get picture on the screen, these rules need to be followed:
- The image file must exist and be conform to the types SFML supports.
- The texture has to in a scope where it exists as long as the image is needed.
- The sprite has to reference the texture.
Am I expected to keep the images around as well, or do the underlying textures share the images?
sf::Image and sf::Texture are both representation of images (i.e. pure memory), thus you actually only need sf::Texture to display something on the screen.
How and when are they released?
The SFML objects use all RAII (google it), thus they get released as soon as they leave the scope.
and the documentation for SFML is hard for me to find.
You mean what you're looking for is hard to find in the doc right?
The doc is easy to find,
here.
If your critique was of the general quality of the C++ code, I would ask you to be quiet. It's tetris.
Don't post stuff nobody should
ever see or comment upon.
I really want your input, but you didn't really give it. It certainly wasn't enough to help the next person who finds this thread, or to keep me from running into other problems because I don't have the proper mental model for how these things interact with each other in SFML (and I mostly mean from a memory standpoint).
Read, learn, experiment.
Do I now get paid for my 30+min essay just for you?