スプライトにタグを指定するやり方をお知らせしましょう。
LevelHelperを起動してください。
タグ名は必ず大文字になります。

タグを設定したいスプライトを選択して
タグを決めちゃいます。

cocos2d-x用にソースの出力を忘れずに!


Xcodeを起動してソースを編集します。
void HelloWorld::ccTouchesEnded(CCSet* touches, CCEvent* event)
{
CCSize s = CCDirector::sharedDirector()->getWinSize();
//Add a new body/atlas sprite at the touched location
CCSetIterator it;
CCTouch* touch;
for( it = touches->begin(); it != touches->end(); it++)
{
touch = (CCTouch*)(*it);
if(!touch)
break;
CCPoint location = touch->getLocationInView();
location = CCDirector::sharedDirector()->convertToGL(location);
// spritesWithTag()メソッドで取得します
CCArray* spritesWithTag = lh->spritesWithTag(ANIMAL);
CCObject* data = NULL;
CCARRAY_FOREACH(spritesWithTag, data) {
LHSprite* spr = (LHSprite*)data;
spr->removeSelf();
}
}
}
これで画面をタップすると
「ANIMAL」タグのスプライトは全て削除されると思います。

スポンサーサイト