kai*_*lor 0 iphone objective-c cocos2d-iphone ios
我希望能够为CCSpriteBatchNode标识一组对象,但还要标识该组的子组.做类似的事情
CCArray *listOfGameObjects = [sceneSpriteBatchNode children];
for (GameObject *tempObject in listOfGameObjects) {
if ([tempObject tag] == kBottleTagValue) {
//make bottle yellow
if ([tempObject tag] == kBrokenBottleTagValue) {
//also make bottle smaller
}
}
}
Run Code Online (Sandbox Code Playgroud)
在该示例中,所有瓶子都将变成黄色,并且如果瓶子也被标记为破碎,则它将变得更小.因此需要使用kBottleTagValue和kBrokenBottleTagValue标记损坏的瓶子.有没有办法做到这一点?因为当我尝试添加两个标签时它失败了.
是的,你可以使用位屏蔽来做到这一点.例如,像这样定义你的标签:
enum
{
kBottleTagValue = 1 << 0;
kBrokenBottleTagValue = 1 << 1;
};
Run Code Online (Sandbox Code Playgroud)
然后标记你的精灵:
[yoursprite setTag:kBottleTagValue|kBrokenBottleTagValue];
Run Code Online (Sandbox Code Playgroud)
要完成,您可以通过执行以下操作来检查您的精灵是否是破碎的瓶子:
CCArray *listOfGameObjects = [sceneSpriteBatchNode children];
for (GameObject *tempObject in listOfGameObjects)
{
if ([tempObject tag] & kBottleTagValue)
{
//make bottle yellow
if ([tempObject tag] & kBrokenBottleTagValue)
{
//also make bottle smaller
}
}
}
Run Code Online (Sandbox Code Playgroud)
我希望它能帮到你.