Can't acces animation


#1

Hello there !

I have a property m9ReloadAnim in the header file, I can access it from the constructor, but when I try to access it from an other function I get an error like: EXC_BAD_ACCESS or something like: “The address does not contain an object”. Please help

I have a header class like this:

`#ifndef SWAT__Weapon
#define SWAT__Weapon

#include “cocos2d.h”

class Weapon : public cocos2d::CCSprite
{
private:
cocos2d::CCAnimation *m9ReloadAnim = cocos2d::CCAnimation::create();
public:
Weapon();
~Weapon();
void reloadM9();
};

#endif`

And a cpp file like this:
@
#include “Weapon.h”
#include “cocos2d.h”

Weapon::Weapon(){
m9ReloadAnim~~>setDelayPerUnit;
}
Weapon::~Weapon{
}
void Weapon::reloadM9{
m9ReloadAnim~~>setDelayPerUnit(1.1f);

}@


#2

You have to retain the object (so it won’t get autoreleased) after creating it, like this:

m9ReloadAnim->retain();


#3

Very good, thanks!