Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CCMutableArray deprecated, how to change code

I am working through the cocos2d-x SimpleGame project, and I am stuck in chapter 5, http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Chapter_5_-_How_to_Detect_the_Collisions.

What I found is that CCMutableArray is deprecated in favor of CCArray. But how do I need to modify the following, to make it work with CCArray (which apparently does not support templates)?

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;
     // (...)
  }
  // (...)
}
like image 597
Ben Avatar asked Aug 03 '26 17:08

Ben


1 Answers

I think it is

CCArray* array1 = CCArray::create();

and later on to use it:

CCObject* arrayItem;
CCARRAY_FOREACH(array1, arrayItem){
    CCSprite* pItem = (CCSprite*)(arrayItem);
    //your code here
}
like image 131
m.ding Avatar answered Aug 06 '26 07:08

m.ding



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!