I want to define a custom non-static method like this:
here is the .h
file
#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__
#include "cocos2d.h"
class HelloWorld : public cocos2d::Scene
{
private:
Director *dir;
SpriteFrameCache *spriteCache;
Size visiableSize;
Vec2 visialbeOrigin;
cocos2d::Sprite getMySpriteByName(const std::string &name);
cocos2d::Sprite getBrickByName(const std::string &name);
public:
static cocos2d::Scene* createScene();
virtual bool init();
// a selector callback
void menuCloseCallback(cocos2d::Ref* pSender);
// implement the "static create()" method manually
CREATE_FUNC(HelloWorld);
};
#endif // __HELLOWORLD_SCENE_H__
And here is how getMySpriteByName()
and getBrickByName
defined in .cpp
file:
cocos2d::Sprite HelloWorld::getMySpriteByName(const std::string &name) {
return Sprite::createWithSpriteFrameName(name);
}
cocos2d::Sprite HelloWorld::getBrickByName(const std::string &name) {
auto brickSprite = this->getMySpriteByName(name);
return brickSprite;
}
But the IDE or the compiler won't let me do that
What have I done wrong?
And the build error is:
Severity Code Description Project File Line Suppression State
Error (active) E0415 no suitable constructor exists to convert from "cocos2d::Sprite *" to "cocos2d::Sprite" onestep d:\cocos\onestep\Classes\HelloWorldScene.cpp 14
Error (active) E0330 "cocos2d::Sprite::Sprite(const cocos2d::Sprite &)" (declared at line 725 of "d:\cocos\onestep\cocos2d\cocos\2d\CCSprite.h") is inaccessible onestep d:\cocos\onestep\Classes\HelloWorldScene.cpp 19
Error (active) E0330 "cocos2d::Sprite::Sprite(const cocos2d::Sprite &)" (declared at line 725 of "d:\cocos\onestep\cocos2d\cocos\2d\CCSprite.h") is inaccessible onestep d:\cocos\onestep\Classes\HelloWorldScene.cpp 20
Error (active) E0020 identifier "visibleSize" is undefined onestep d:\cocos\onestep\Classes\HelloWorldScene.cpp 51