1
SFML projects / Re: [2D Platformer] Melting Saga
« on: April 04, 2016, 09:24:58 am »
Hi! I was wondering how did you implement the updater. The game looks neat btw.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Is your error compile-time or run-time? Are you trying to erase any elements while iterating?
I declared an iterator in my header file and after I push back a state inside the vector I reset the iterator like this:Why do you declare an iterator in a header? Is it global?
Iterators are objects of extremely local scope. In most cases, it's an error to store them -- they're used for iteration, and they become invalid as the underlying container changes.Don't do that! Declare the iterator locally, that is, inside the for loop.for (it = states.begin(); it != states.end(); ++it)
{
(*it)->update(window, dt);
}
Or use range-based for loops directly.
I cannot use the range-based for loop since the iterator must be updated. I tested this out, when I try to enter the PlayState for example, I get an error when the state is getting pushed back: Vector iterator not incrementable. The only way for this to work is to use:for (auto i = 0; i < states.size(); i++)Or:for (auto it = states.begin(); it != states.end(); ++it )EDIT: The second for loop gives the same error as the range-based. So the first for is the only one that's working.
Would you mind giving some context to this error? Because that's no supposed to happen.
I though it would be cool to use a transparent splashscreen.http://en.sfml-dev.org/forums/index.php?topic=18217
http://en.sfml-dev.org/forums/index.php?topic=13904
http://en.sfml-dev.org/forums/index.php?topic=17947
http://en.sfml-dev.org/forums/index.php?topic=18337
http://en.sfml-dev.org/forums/index.php?topic=16776
These should help
I was aiming for window transparency.
Why exactly would you want to do that?
But preferably, lay off the use of dynamically-allocated memory.
2. Prefer for (std::unique_ptr<State>& state : states) { ... } to for (int i = 0; i < vec.size(); i++) { ... }.
What you could possibly do instead is add some pause and resume functions to your state, and give your states access to your state manager (pass a reference on each function call). What this could allow you to do is check if the newest state is an inventory state (via using dynamic_cast on it's pointer), and rather that halting the gameplay (which you could do if the state is something else), you could call some special function your inventory state has to pass a reference to your in-game state and have your inventory manually update your in-game state itself, but under special conditions (such as disabling input to your player while in the inventory menu, darkening things around the inventory menu, or whatever).
I'm not sure exactly what your goals were