cocos2dx碰撞检测实现(2)
来源:未知 责任编辑:责任编辑 发表时间:2013-12-06 08:43 点击:次
p> CCArray* targetsToDelete =new CCArray;
p> CCObject* it = NULL;
p> CCObject* jt = NULL;
p>
p> CCARRAY_FOREACH(_bullet, it)
p> {
p> CCSprite *projectile = dynamic_cast<CCSprite*>(it);
p> CCRect projectileRect = CCRectMake(
p> projectile->getPosition().x - (projectile->getContentSize().width/2),
p> projectile->getPosition().y - (projectile->getContentSize().height/2),
p> projectile->getContentSize().width,
p> projectile->getContentSize().height);
p>
p> CCARRAY_FOREACH(_target, jt)
p> {
p> CCSprite *target = dynamic_cast<CCSprite*>(jt);
p> CCRect targetRect = CCRectMake(
p> target->getPosition().x - (target->getContentSize().width/2),
p> target->getPosition().y - (target->getContentSize().height/2),
p> target->getContentSize().width,
p> target->getContentSize().height);
p>
p> if (projectileRect.intersectsRect(targetRect))
p> {
p> targetsToDelete->addObject(target);
p> projectilesToDelete->addObject(projectile);
p> }
p> }
p> }
p>
p> CCARRAY_FOREACH(targetsToDelete, jt)
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>