Cocos2dxでアプリの開発をしており、キャラにアニメーションをつけようと思いこちらのサイトを参考にさせていただいたのですが(直リンで申し訳ありません)、
https://takachan.hatenablog.com/entry/2017/08/16/010311
派生元のcovos2d::Nodeやcocos2d::Spriteのメンバ変数・関数を参照しようとすると、「Cannot initialize object parameter of type 'cocos2d::Node'('cocos2d::Sprite') with an expression of type 'CharacterChip'」というエラーが出てしまい、開発が進みません。
原因としてはどんなものが考えられるのでしょうか…
ヘッダーと実装はこちらになります。
c++
1class CharacterChip : public cocos2d::Sprite{ 2private: 3 //現在向いている方向 4 Direction _currentDir = (Direction)-1; 5 //各方向のアニメーションを記憶しておく入れ物 6 cocos2d::Map<Direction, cocos2d::Action*> animationTable; 7 8public: 9 //リソースを解放してオブジェクトを破棄 10 virtual ~CharacterChip(); 11 virtual bool init(const std::string& name); 12 static CharacterChip* create(const std::string& name); 13 void changeDirection(Direction dir); 14};
c++
1CharacterChip::~CharacterChip(){ 2 this->removeFromParentAndCleanup(true); //ここにCannot initialize object parameter of type 'cocos2d::Node' with an expression of type 'CharacterChip'というエラー 3 this->animationTable.clear(); 4} 5 6bool CharacterChip::init(const std::string& name){ 7 if(!Sprite::init()) //ここにCannot initialize object parameter of type 'cocos2d::Sprite' with an expression of type 'CharacterChip'というエラー 8 return false; 9 10 auto baseSprite = Sprite::create(name); 11 auto textureSource = baseSprite->getTexture(); 12 textureSource->setAliasTexParameters(); 13 14 int frameWidth = baseSprite->getContentSize().width/4; 15 int frameHeight = baseSprite->getContentSize().height; 16 this->setContentSize(Size(frameWidth, frameHeight));//ここにCannot initialize object parameter of type 'cocos2d::Sprite' with an expression of type 'CharacterChip'というエラー 17 int harfWidth = baseSprite->getContentSize().width/2; 18 19 for(int y = 0; y < 2; y++){ 20 auto animation = Animation::create(); 21 animation->setDelayPerUnit(0.3f); 22 animation->setRestoreOriginalFrame(true); 23 for(int x = 0; x < 2; x++){ 24 int _x = frameWidth * x + (y >= 1 ? harfWidth : 0); 25 int _y = 0; 26 animation->addSpriteFrameWithTexture(textureSource, Rect(_x, _y, frameWidth, frameHeight)); 27 } 28 this->animationTable.insert((Direction)y, RepeatForever::create(Animate::create(animation))); 29 } 30 return true; 31} 32 33CharacterChip* CharacterChip::create(const std::string& name){ 34 CharacterChip* pRet = new (std::nothrow) CharacterChip(); 35 if(pRet && pRet->init(name)){ 36 pRet->autorelease(); //ここにCannot initialize object parameter of type 'cocos2d::Ref' with an expression of type 'CharacterChip'というエラー 37 return pRet; 38 }else{ 39 delete pRet; 40 pRet = nullptr; 41 return nullptr; 42 } 43} 44 45void CharacterChip::changeDirection(Direction dir){ 46 if(this->_currentDir == dir) 47 return; 48 if(this->animationTable.find(dir) == this->animationTable.end()) 49 return; 50 this->runAction(this->animationTable.at(dir)); 51}
エラーが全て似たような感じなので、原因がわかれば一気に解決できそうなのですが...
実体がないというのも、create関数中にエラーが出ていることが関係しているのではと思います。
CharacterChipクラスは、Spriteクラス、Nodeクラス、Refクラスを全て継承しているはずなのに、なぜその派生元のクラスのメンバ変数やメンバ関数をいじれないんでしょう泣
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。