「ios開発」CCArrayの使い方を纏める

1.配列に要素を追加
CCSprite* pRet=CCSprite::create(“test.png");
pArray->addObject(pRet);

2.要素を削除
pArray->removeObject(pRet);
pArray->removeObjectAtIndex(0);

3. foreachの使い方
CCObject* pObj;
//フォワード
CCARRAY_FOREACH(s_pBulletArray,pObj)
{
CMapNode* pNode=(CMapNode*)pObj;
}
//逆方向
CCARRAY_FOREACH_REVERSE(s_pBulletArray,pObj)
{
CMapNode* pNode=(CMapNode*)pObj;
}

4.forループ遍歴
for (unsigned int i = 0; i <s_pBulletArray->count(); ++i)
{
CCNode* pObj=(CCNode*)s_pBulletArray->objectAtIndex(i);
}

for (int i = arr->count()-1; i>=0 ; –i)

{
CMonster* pObj=(CMonster*)arr->objectAtIndex(i);
bool isCollide = false;
isCollide =rect.intersectsRect(pObj->getCollideRect());
if (isCollide)
{
arr->removeObject(pObj);
}
}

IOS

Posted by arkgame