I read this tutorial https://github.com/SFML/SFML/wiki/Source:-AnimatedSprite and tried to implement it myself, but it's not completely working.
Everything is fine except for this line from the example code:
animatedSprite.play(*currentAnimation);
When I run the program with that line, the following error occurs: http://i.imgur.com/ckpzfdk.png
Does anyone know how to fix that? When I for example use the following code instead of the code above everything runs fine
animatedSprite.play(walkingAnimationLeft);
But of course that's not what I want. I want the play the currentAnimation.
Thanks for the reply. This is the call stack:
> msvcp110d.dll!std::_Debug_message(const wchar_t * message, const wchar_t * file, unsigned int line) Line 15 C++
test.exe!std::vector<sf::Rect<int>,std::allocator<sf::Rect<int> > >::operator[](unsigned int _Pos) Line 1124 C++
test.exe!Animation::getFrame(unsigned int index) Line 22 C++
test.exe!AnimatedSprite::setFrame(unsigned int newFrame, bool resetTime) Line 68 C++
test.exe!AnimatedSprite::setAnimation(const Animation & animation) Line 39 C++
test.exe!AnimatedSprite::play(const Animation & animation) Line 49 C++
test.exe!Game::update(sf::Time deltaTime, float fps) Line 104 C++
test.exe!MainClass::operator()() Line 111 C++
test.exe!main(int argc, char * * argv) Line 15 C++
test.exe!_WinMain@16() Unknown
test.exe!__tmainCRTStartup() Line 528 C
test.exe!WinMainCRTStartup() Line 377 C
kernel32.dll!755a336a() Unknown
[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]
ntdll.dll!77939f72() Unknown
ntdll.dll!77939f45() Unknown
It looks like the error is in the Animation class, maybe the std::vector<sf::IntRect> m_frames;
?
I use the same code from the tutorial so I don't really know what's wrong
I think the problem are these two functions from the Animation class. const sf::IntRect &getFrame(std::size_t n) const;
void addFrame(sf::IntRect rect);
I used some couts to check whether frames were added when the function addFrame was called. getSize() correctly prints 4 frames after adding them to each animation. But when I cout getSize() from within const sf::IntRect &getFrame(std::size_t n) const;
it prints 0, so obviously somehow the frames weren't added after all even though it said otherwise in the addFrame function...
It's really weird