iphone - 在 CCMenu 内从批处理节点添加 Sprite 而不增加绘制调用数量的正确方法

标签 iphone ios ipad cocos2d-iphone

假设我正在使用 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/

相关文章:

iphone - 调用 [tableView reloadData] 恢复帧变化

ios - 如何在 UIWebViewDelegate#didFailLoadWithError 中获取 NSURLRequest?

javascript - 调用phonegap摄像头功能后出现空白

iphone - iOS 自定义 TabBar 高度

iphone - 将 SQLite 中的数据保存为 BLOB 是一种良好的编程习惯吗?

javascript - HTML5 Canvas(绘图(矩形)不断消失)

iphone - SKStoreProductViewController 和 GKHostedAuthenticateViewController 没有 iPhone 横向模式

ios - 快速错误: Could not find an overload for '-' that accepts the supplied arguments

ios - 在纵向和横向模式下为 iPad 设置不同的约束

ios - 谁能帮我解决这个 xcode 问题?