I’ve been attempted to extend the sprite class with cocos alpha. I’m not having any luck. I’m VERY new to C++ with a long background in scripting languages. This is what I have:
Header
#include <iostream>
#include "cocos2d.h"
#include "GameSelectionScene.h"
using namespace cocos2d;
class CoinTally : public cocos2d::Sprite {
public:
virtual bool init();
CoinTally();
virtual ~CoinTally();
};
Solution was a different approach using Director::getInstance()->getRunningScene();
I needed a class to run operations that many scenes needed. Using a simple class that did not extend any but accessed the current running scene proved a better solution. I’m not sure if this is the most optimal approach, but it let me abstract my code.
/// H FILE
#include <iostream>
#include "cocos2d.h"
using namespace cocos2d;
class CoinTally {
public:
bool init();
};
/// CPP FILE
using namespace cocos2d;
bool init(){
auto scene = Director::getInstance()->getRunningScene();
auto coin = Sprite::createWithSpriteFrameName("coin-01.png");
scene->addChild(coin);
return true;
};