重写init()方法,Cocos2d-x v2.2
Overriding the init() method , Cocos2d-x v2.2
我似乎无法在我的类中重写init()方法,这是CCLayer的子类。我能够重写create()方法。所有我需要做的是传递一个int当我创建层的init()方法:下面是create (int n)方法
CCLayer* Stage::create(int n)
{
CCLayer *pRet = new CCLayer();
if (pRet && pRet->init(n))
{
pRet->autorelease();
return pRet;
}
else
{
CC_SAFE_DELETE(pRet);
return NULL;
}
}
bool DuneStage::init(int ss)
{
// this code should execute
}
.h文件:
virtual bool init(int n);
static CCLayer* create(int z);
我还需要在cleer .cpp文件中重写此方法吗?
bool CCLayer::init()
{
bool bRet = false;
do
{
CCDirector * pDirector;
CC_BREAK_IF(!(pDirector = CCDirector::sharedDirector()));
this->setContentSize(pDirector->getWinSize());
m_bTouchEnabled = false;
m_bAccelerometerEnabled = false;
// success
bRet = true;
} while(0);
return bRet;
}
重写的方法签名必须是父类方法virtual bool init()
如果你想发送参数,那么你可以在你的CCLayer子类中声明它们作为成员变量,然后在create
方法中调用init
方法之前分配它们。
CCLayer* Stage::create(int n)
{
CCLayer *pRet = new CCLayer();
pRet->n = n
...........
...........
}
Stage* Stage::create(int n)
{
Stage* pRet = new Stage();
pRet->n = n
...........
...........
}
相关文章:
- 如何修改代码以打印出数组 v2
- 提升精神 V2 Qi 语法线程安全吗?
- 如何在 cpp 中解压缩数字,如果它们是使用 struct.pack(fmt, v1, v2, ..) 打包在 pyth
- 构造对象 c++ (cocos2d-x) 时的区别
- Microsoft NTLM (v2) 中的时间戳使用
- 将 aws-iot-device-sdk-cpp-v2 与 CMake 结合使用
- 无法驱动带有 Adafruit 电机屏蔽 V2.3 的直流电机
- 将Kinect v2帧速率(rgb、深度、骨架)设置为每秒25帧
- 如何避免 Cocos2d-x 3.15.1 中的 MenuItemImage 和 MenuItemSprite 之间的冲突
- Cocos2D-X:从内存中读取 MP3 数据
- 如何在 cocos2d-x 3.17v 中创建字符串数组
- 精神V2和X3的状态性
- 在 UWP 中使用C++录制 Kinect V2.0(颜色和深度)
- 如何使用 cocos creator 在 Cocos2d-X/Cocos2d-JS 中调用 javascript 函数并
- 音乐和音效无法在win32平台上播放?(Cocos2D-X)
- Cocos2d-x TiledMap,在调用 getLayer() 获取碰撞层时返回一个 nullptr?
- Kinect V2 已閱讀深度問題
- Xcode 6.3 Apple Match-O链接器错误,带有COCOS2D v2.1.5项目
- 将Cocos2d-x v2.2.5集成到Marmalade中
- 重写init()方法,Cocos2d-x v2.2