.h 文件
#include "cocos2d.h"
class MyHelloCandy : public cocos2d::Layer
{
public:
static cocos2d::Scene* createScene();
virtual bool init();
CREATE_FUNC(MyHelloCandy);
private:
int m_No; //输入的数字
void Input_No(cocos2d::Ref* pSender,int data);
void XianSuo(cocos2d::Ref* pSender);
Label* Input_No_label; //输入的数字标签
void create_No_label();
};
```
.cpp文件:
void MyHelloCandy::create_No_label()
{
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
Input_No_label = Label::createWithTTF(Value(m_No).asString(), "fonts/Marker Felt.ttf", 24);
Input_No_label->setPosition(Vec2(origin.x + visibleSize.width/2+30,
origin.y + visibleSize.height/2+100));
this->addChild(Input_No_label, 1);
}
void MyHelloCandy::Input_No(Ref* pSender,int data)
{
.....................
Input_No_label->setString(String::createWithFormat("%s",Value(m_No).asString())->getCString);
.........................
}
```
会报错:
错误 7 error C2065: “Input_No_label”: 未声明的标识符 e:\cocospro\myhellocandy\classes\myhellocandyscene.cpp 164 1 MyHelloCandy
错误 8 error C2065: “Input_No_label”: 未声明的标识符 e:\cocospro\myhellocandy\classes\myhellocandyscene.cpp 165 1 MyHelloCandy
错误 10 error C2065: “Input_No_label”: 未声明的标识符 e:\cocospro\myhellocandy\classes\myhellocandyscene.cpp 167 1 MyHelloCandy
错误 11 error C2065: “Input_No_label”: 未声明的标识符 e:\cocospro\myhellocandy\classes\myhellocandyscene.cpp 204 1 MyHelloCandy