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,再在这里使用。

    评论

报告相同问题?

悬赏问题

  • ¥20 蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏