It's interesting that it runs so often. :-D
You're declaring the animations in the constructor, this means as soon as you leave the constructor the animation pointer will get invalid. Funny enough it seems like the data in memory is still kept there sometimes, thus the pointer can access it.
Make your animation ptr a member variable and you should be good. ;-)
Sorry I am very new to programming... Are you saying that I should make a member function something like InitilizeAnimation(); and place that in the constructor.. then put all the animation initialisation code for the animation in hat function and then call the function from the constructor?
This is the header as it is for the header...
#ifndef GOPAC_H
#define GOPAC_H
#include "Debug.h"
#include "SFML/Graphics.hpp"
#include "Thor/Animation.hpp"
#include "GameObject.h"
class goPac : public GameObject
{
public:
enum {STOPPED, LEFT, RIGHT, UP, DOWN};
goPac();
~goPac();
void Update(sf::RenderWindow&, sf::Event&, float);
void Draw (sf::RenderWindow&);
private:
float _velocity;
float _maxVelocity;
float _startofTimer;
int _nextDirection;
// Sprite Animation
sf::Sprite _PACsprite;
sf::Clock animClock;
thor::FrameAnimation defaultAnim;
thor::FrameAnimation chomp;
thor::Animator<sf::Sprite, std::string> animPac;
void playAnimation();
};
#endif // - GOPAC_H
Make your animation ptr a member variable and you should be good. ;-)
This is the question I have... I am not declaring any pointers in the code I posted...
edit
oh you mean
thor::FrameAnimation defaultAnim;
?? I'll try this
edit2
I think you mean this? All I did was comment out the marked lines,
goPac::goPac()
: _nextDirection(STOPPED)
, _velocity(10.0f)
, _maxVelocity(100.0f)
{
_PACsprite.setTexture(*TextureManager::getInstance().rSpriteSheet());
//thor::FrameAnimation defaultAnim; // This is in the .h file WTF am I doing?
defaultAnim.addFrame(1.f, sf::IntRect(40, 80, 40, 40));
// Create animation: CHOMP
//thor::FrameAnimation chomp; // This is in the .h file WTF am I doing?
chomp.addFrame(1.f, sf::IntRect(120, 80, 40, 40));
chomp.addFrame(1.5f, sf::IntRect(160, 80, 40, 40));
chomp.addFrame(1.f, sf::IntRect(120, 80, 40, 40));
chomp.addFrame(2.f, sf::IntRect(40, 80, 40, 40));
animPac.setDefaultAnimation(defaultAnim, sf::seconds(1.f));
animPac.addAnimation("chomp", chomp, sf::seconds(0.4f));
}