I can’t get passed Chapter 5 How to Detect the Collisions
http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Chapter_5__How_to_Detect_the_Collisions>getContentSize.width/2),
The method " void HelloWorld::update " doesnt compile in version 2.0.4
I found out that I had to replace ccTime with float, but the rest of the code doesn’t work and I cant seem to find an answer.
The main problem with this method is dat it uses CCMutableArrayIterator.
I’ve rewritten the method with some tips I found on the internet. The game compiles, but the collision doesnt work.
This is what I’ve came up with:
void HelloWorld::update
{
CCArray projectilesToDelete = new CCArray;
CCObject arrayItem;
CCARRAY_FOREACH{
CCSprite* projectile = ;
CCRect projectileRect = CCRectMake.x
~~ (projectile
projectile~~>getPosition().y
- (projectile~~>getContentSize.height/2),
projectile~~>getContentSize().width,
projectile~~>getContentSize.height);
CCArray targetsToDelete = new CCArray;
CCARRAY_FOREACH{
CCSprite target = ;
CCRect targetRect = CCRectMake.x~~ (target~~>getContentSize.width/2),
target~~>getPosition().y - (target~~>getContentSize.height/2),
target~~>getContentSize().width,
target~~>getContentSize.height);
if )
{
targetsToDelete~~>addObject(target);
}
}
CCARRAY_FOREACH(targetsToDelete, arrayItem){
CCSprite* target = (CCSprite*)(arrayItem);
*targets~~>removeObject;
this~~>removeChild;
}
if >0)
{
projectilesToDelete~~>addObject;
}
targetsToDelete~~>release;
}
CCARRAY_FOREACH{
CCSprite* projectile = ;
*projectiles~~>removeObject;
this~~>removeChild(projectile, true);
}
projectilesToDelete->release();
}