-[CCSprite setTexture:]中的断言失败

问题描述

|| 我正在开发的iPhone的cocos2d应用程序有问题。有时在场景更改期间会出现问题。应用程序卡住,控制台开始打印以下语句: -[CCSprite setTexture:]中的断言失败 我希望您向我建议调试它的正确方法,因为该问题并非总是会发生,并且没有确切的迹象表明错误可能在哪里。 先感谢您 ...几个小时后:出现内存警告后出现问题。因此,这是由于精灵缓存在动画正在利用缓存的纹理图集和相关图纸时刷新的。我该怎么办?     

解决方法

        我将在
[CCSprite setTexture:]
中设置一个断点,然后从那里检查堆栈跟踪并返回到您的冒犯电话。当然,只有在发生故障的情况下,这才会成功。 在我的cocos2d安装(0.9.5)中,ѭ1中的断言可以是:
NSAssert( ! usesBatchNode_,@\"CCSprite: setTexture doesn\'t work when the sprite is rendered using a CCSpriteBatchNode\");

// accept texture==nil as argument
NSAssert( !texture || [texture isKindOfClass:[CCTexture2D class]],@\"setTexture expects a CCTexture2D. Invalid argument\");
因此,您做错了任何一个。 评论后编辑: 您的appDelegate大概定义为:
 - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
[[CCDirector sharedDirector] purgeCachedData];
 }
尝试使用:
[[CCTextureCache sharedTextureCache] removeUnusedTextures];
而不是
[[CCDirector sharedDirector] purgeCachedData]
。希望情况会有所改善。     

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...