zl程序教程

您现在的位置是:首页 >  其它

当前栏目

关于Cocos2d-x中自定义的调用注意事项

关于 自定义 调用 注意事项 cocos2d
2023-09-11 14:21:19 时间

1.在实例类Student.h中定义一个自己的方法

public:

int getSno();

 

2.在实例类Student.cpp中实现这个方法

int Student::getSno()
{
  return sno;
}

 

3.在游戏场景类HelloWorld.h中声明这个实例类的对象

private:

Student *stu; //注意这里必须是Student类型的才能使用getSno方法,如果是Sprite类型的则会提示没有这个方法

 

4.在游戏场景类HelloWorld.cpp中用这个实例类的对象去调用我们自定义的方法

stu = Student::create();
sno = stu->getSno();