Identify the problem (a.k.a "complete and minimal code")
At this point you're about to write your post. Many people will read it and try to help, but none of them have hours to spend on your problem. So it is a very bad idea to copy-paste pieces of your original code, or even worse, the whole thing.
Why is it a bad idea? Because:So, let's say you have a problem when displaying a sprite. Nobody cares about how you check collisions, how you play sounds, how you export your game files, etc... It would just be a waste of time to read this code. So what you must do is to extract the relevant lines of code from your application and write a new piece of code that contains only them. We don't care if the new code doesn't do exactly what your original application does, all it has to do is to reproduce the problem.
- your code contains 95% of code which is irrelevant to the problem
- people just give up reading when they see too much code
- people can't test it themselves
- everybody loses precious time because the problem is lost in tens or hundreds of lines of code
It is important that:While reducing the code, chances are that you solve the problem yourself: things are clearer and more obvious with less code. And if you can't find anything, we will most likely give you an answer very quickly because the code to examine is very small.
- the code is complete, so people can test it
- the code is as simple as possible, the best is one main() with all the code inside -- people don't want to setup a complex project just to test your code
- the code reproduces the initial problem
- the application doesn't depend on external resource files (unless it's related to the problem)
The problem with your post is, that you didn't read/follow this thread (http://en.sfml-dev.org/forums/index.php?topic=5559.0), especially the following part:Quote from: Read Before Posting (http://en.sfml-dev.org/forums/index.php?topic=5559.msg36368#msg36368)Identify the problem (a.k.a "complete and minimal code")
At this point you're about to write your post. Many people will read it and try to help, but none of them have hours to spend on your problem. So it is a very bad idea to copy-paste pieces of your original code, or even worse, the whole thing.
Why is it a bad idea? Because:So, let's say you have a problem when displaying a sprite. Nobody cares about how you check collisions, how you play sounds, how you export your game files, etc... It would just be a waste of time to read this code. So what you must do is to extract the relevant lines of code from your application and write a new piece of code that contains only them. We don't care if the new code doesn't do exactly what your original application does, all it has to do is to reproduce the problem.
- your code contains 95% of code which is irrelevant to the problem
- people just give up reading when they see too much code
- people can't test it themselves
- everybody loses precious time because the problem is lost in tens or hundreds of lines of code
It is important that:While reducing the code, chances are that you solve the problem yourself: things are clearer and more obvious with less code. And if you can't find anything, we will most likely give you an answer very quickly because the code to examine is very small.
- the code is complete, so people can test it
- the code is as simple as possible, the best is one main() with all the code inside -- people don't want to setup a complex project just to test your code
- the code reproduces the initial problem
- the application doesn't depend on external resource files (unless it's related to the problem)
Reduce the code and we'll take a look at it. :)
- the code is complete, so people can test it
- the code is as simple as possible, the best is one main() with all the code inside -- people don't want to setup a complex project just to test your code
Unfortunately you didn't read the full quote, because you missed the following two very important points:Quote
- the code is complete, so people can test it
- the code is as simple as possible, the best is one main() with all the code inside -- people don't want to setup a complex project just to test your code
The idea essentially is to get a code base that only loads and plays the sound, without the whole stuff for your entities and collision parts. If that doesn't yield a problem, then you can add some very simplified entity logic. Doing so, you might find a cause of the issue yourself.
The other way around where you have the full source and slowly remove pieces works as well, but can be a bit harder.
I currently can't see where the problem is in the code. If you have preloaded the sound and then call play(), it should instantly play the sound.
Btw what's the actual issue here? Is it the window that doesn't show? Or is it the sound that doesn't play? Or is it the delay you have till a sound plays? Or is it the collision that you have problem with?
Whats wrong with enumeration?Wrong is that you don't use the language and library features (arrays, containers) for collections of similar objects. It makes code longer as well as more difficult to read, to maintain, to extend and to debug. Code duplication is simply bad practice that can be easily avoided.
C++ is so unforgiving :(True, but that's not a C++ problem. Code duplication is bad in any language.