我正在完成 cocos2d-x SimpleGame 项目,但卡在第 5 章,http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Chapter_5_-_How_to_Detect_the_Collisions .
我发现 CCMutableArray 已被弃用,取而代之的是 CCArray。但是我需要如何修改以下内容才能使其与 CCArray(显然不支持模板)一起工作?
HelloWorldScene.h
cocos2d::CCMutableArray<cocos2d::CCSprite*> *_projectiles;
HelloWorldScene.cpp
// in init()
// Initialize arrays
_projectiles = new CCMutableArray<CCSprite*>;
HelloWorld::~HelloWorld()
{
if (_targets)
{
_projectiles->release();
_projectiles = NULL;
}
}
HelloWorld::HelloWorld()
:_projectiles(NULL)
{
}
void HelloWorld::update(float dt)
{
CCArray *projectilesToDelete = new CCArray<CCSprite*>;
CCMutableArray<CCSprite*>::CCMutableArrayIterator it, jt;
for (it = _projectiles->begin(); it != _projectiles->end(); it++)
{
CCSprite *projectile = *it;
// (...)
}
// (...)
}
最佳答案
我觉得是
CCArray* array1 = CCArray::create();
稍后使用它:
CCObject* arrayItem;
CCARRAY_FOREACH(array1, arrayItem){
CCSprite* pItem = (CCSprite*)(arrayItem);
//your code here
}
关于cocos2d-iphone - CCMutableArray 已弃用,如何更改代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11729769/