假设我正在使用 CCSpriteFrameCache 并添加这样的帧
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"atlas.plist"];
mySpriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"atlas.png"];
CCSprite *oneSprite = [CCSprite spriteWithSpriteFrameName:@"abc"]; //yes I do not use extensions, who need them?
[mySpriteSheet addChild:oneSprite];
这效果非常好。您可以在不增加绘制调用的情况下向 mySpriteSheet 添加大量 Sprite ,但假设我想在 CCMenuItem 内使用这些 Sprite ,或者在本例中 CCMenuItemSprite 是 CCMenuItem 的子类,如下所示:
CCSprite *spriteNormal = [CCSprite spriteWithSpriteFrameName:imagemNormal];
CCSprite *spriteHighlight = [CCSprite spriteWithSpriteFrameName:imagemHighlight];
CCMenuItemSprite *myItem = [CCMenuItemSprite itemWithNormalSprite:spriteNormal
selectedSprite:spriteHighlight
target:target
selector:@selector(doSomething)];
然后该项目进入 CC 菜单
CCMenu *menu = [CCMenu menuWithItems:myItem, nil];
现在,问题来了。如果我这样做
[self addChild:menu];
绘制调用将会增加,即使是来自批处理节点的 Sprite ,我也做不到
[mySpriteSheet addChild:menu];
因为它会崩溃。
我该怎么做?
最佳答案
简短回答:你不能。
长答案(也不完全是):您必须编辑 CCMenu 的代码才能使其工作。恕我直言,不值得这么麻烦,编写自己的支持批处理的按钮/菜单类要容易得多。
关于iphone - 在 CCMenu 内从批处理节点添加 Sprite 而不增加绘制调用数量的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15073640/