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 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误