zwqStella 2015-07-15 14:08 采纳率: 0%
浏览 6184

明明在类中定义了成员,为什么找不到标识符?

类定义如下:

class HelloWorld : public cocos2d::Layer
{
private:

Sprite *beijing;
Sprite *cangshu;
Sprite *guazi1;

public:
// there's no 'id' in cpp, so we recommend returning the class instance pointer
static cocos2d::Scene* createScene();

// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
virtual bool init();

// a selector callback
void menuCloseCallback(cocos2d::Ref* pSender);

// implement the "static create()" method manually
CREATE_FUNC(HelloWorld);


//菜单
void Menutest(Ref *ref);

};

在init中的调用:

bool HelloWorld::init()
{
//前边是初始化的语句,下边是创建精灵的语句 ........
// add "HelloWorld" splash screen"
beijing = Sprite::create("beijing.jpg"); //这里开始提示找不到标识符
cangshu = Sprite::create("cangshu.png");
guazi1 = Sprite::create("guazi1.png");
setTouchEnabled(true);

// position the sprite on the center of the screen
beijing->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
beijing->setScale(2.2);
cangshu->setPosition(Vec2(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y));
guazi1->setPosition(Vec2(visibleSize.width / 2 + origin.x , visibleSize.height / 2 + origin.y ));

// add the sprite as a child to this layer
this->addChild(beijing, 0 , beijing_tag);
this->addChild(cangshu, 1 , cangshu_tag);
this->addChild(guazi1, 2 , guazi1_tag);

因为作业射击游戏刚接触Cocos 2d-x的小白一枚。。。
如图,明明在类中定义了成员变量,但是在init函数里调用的时候却说找不到标识符??为什么呢?之前还尝试过把Sprite定义为全局变量,但是这样编译通过,调试报错,那么到底怎样才能定义一个到处都可以用的Sprite变量呢

  • 写回答

4条回答 默认 最新

  • 91program 博客专家认证 2015-07-15 14:27
    关注

    图看不到哦,没有办法。
    你需要将图上传到 CSDN,再在这里使用。

    评论

报告相同问题?

悬赏问题

  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺