如何在Cocos2d-x中永久移除精灵
How to remove a sprite permanently in Cocos2d-x
我正在使用cocos2d-x开发游戏。我想永久移除精灵。我有两杯雪碧。在精灵之间制造碰撞。当碰撞发生时,我想永久移除这些精灵。我使用以下代码来制作碰撞&删除精灵。
CCARRAY_FOREACH(_sprrand24, stwentyfour)
{
CCSize size=sprrand24->getContentSize();
CCSprite *sprrand24 = dynamic_cast<CCSprite*>(stwentyfour);
CCRect sprrand24Rect = CCRectMake(
sprrand24->getPosition().x - (size.width/2),
sprrand24->getPosition().y - (size.height/2),
size.width/2,
size.height/2);
CCARRAY_FOREACH(_sprrand25, stwentyfive)
{
CCSize size=sprrand25->getContentSize();
CCSprite *sprrand25 = dynamic_cast<CCSprite*>(stwentyfive);
CCRect sprrand25Rect = CCRectMake(
sprrand25->getPosition().x - (size.width/2),
sprrand25->getPosition().y - (size.height/2),
size.width/2,
size.height/2);
if (sprrand24Rect.intersectsRect(sprrand25Rect))
{
this->removeChild(sprrand24, true);
this->removeChild(sprrand25, true);
}
}
}
要删除精灵,可以使用
sprrand24.removeFromParentAndCleanup(true);
如果你为每个精灵分配一个tag
,那么你就可以分配removeChildByTag(tag);
sprite->setTag(99); // i made this up
this->removeChildByTag(99);
相关文章:
- 为什么精灵在 cocos2d-x 中颤抖
- 在 Cocos2d-x 中一次使用多个精灵表
- cocos2d-x每次我需要精灵或只是改变它的纹理时,制作精灵的最佳做法是什么
- Cocos2d中精灵的暂停/简历动作/动画
- 为什么Cocos2D-X不一第一次显示精灵
- 如何在cocos2d-x3测试版中围绕精灵绘制边界框
- COCOS2D-X:从另一个线程中加载精灵,任何模式
- 如何使用Cocos2D-X中的精灵表创建菜单
- Cocos2d-x CCArray-对象和精灵
- Cocos2d-x-从精灵或纹理数据编码base64字符串
- 在 cocos2d-x v3 中绘制并向场景添加大量精灵(~200)的最佳方法是什么?
- Cocos2d-x V3.2.使用 RenderTexture 创建精灵
- 捕获精灵及其所有子项 - Cocos2D-X 3.2
- 在4x6网格中显示和随机化精灵-Cocos2d-x
- 如何在cocos2d-x2.1.4中复制精灵的精灵
- Cocos2d-xTMX地图与游戏精灵共享纹理图像文件
- Cocos2d-x拖动手指,精灵以稳定的速度跟随
- 如何在Cocos2d中添加一个始终在屏幕上的精灵
- Cocos2d-x:在多个精灵上运行的顺序动作
- Cocos2d-x 3.2 EventListener在子精灵中不工作