2010-04-14 104 views
2

如何避免不必要的重新分配?我运行这段代码:当animaton运行(当然 - 它难看)Cocos2d中的动画制作精灵

CCSpriteFrameCache * cache = [CCSpriteFrameCache sharedSpriteFrameCache]; 
    [cache addSpriteFramesWithFile:@"boosttexture.plist"]; 

    CCAnimation * animation = [[CCAnimation alloc] initWithName:@"boosting" delay:1/24.0f]; 

    [animation addFrame:[cache spriteFrameByName:@"ship.png"]]; 
    [animation addFrame:[cache spriteFrameByName:@"ship_boost_l_r.png"]]; 

    id action = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:animation]]; 
    [spaceShipSprite runAction:action]; 

,我得到这个在控制台:

2010-04-14 13:40:16.311 Booster2K10Beta [521:20b] cocos2d:释放CCSpriteFrame = 00EBA620 | TextureName = 4,Rect =(1.00,32.00,32.00,32.00)

2010-04-14 13:40:16.411 Booster2K10Beta [521:20b] cocos2d:释放CCSpriteFrame = 00EBA620 | TextureName = 4,Rect =(1.00,32.00,32.00,32.00)

2010-04-14 13:40:16.496 Booster2K10Beta [521:20b] cocos2d:释放CCSpriteFrame = 00EBA620 | TextureName = 4,Rect =(1.00,32.00,32.00,32.00)

似乎不必要的是同一个SpriteFrame每秒会释放24次 - 我该如何避免这种情况?

回答

1

我假设你有CCDEBUG变为2.把它放回1.这就是你看到的CCLOGINFO的东西。尽管如此,仍然使用Xcode的分析工具来查看内存是否正在流失。我打赌不是。你只是看到你还不明白的东西。