【发布时间】:2011-04-23 04:33:17
【问题描述】:
我从 Cocos2D 板上得到了 0 个响应,所以我想我在这里试试。
好的。我为此扯掉了我的头发。昨晚我对我的代码进行了彻底的重新调整,希望能解决一些 iphone4 帧率问题。我提前创建了精灵,而不是在更新方法期间进行一些创建。我现在只根据需要在 update 方法中将它们添加到 spritesheet 中。
但是,这确实没有解决问题。所以我出于好奇改变了一件事情。我的主要精灵表是 2048x2048,包含 24 个帧和一个静态帧。我曾经从使用 spriteWithSpriteFrameName 生成的帧中提取静态图像。相反,我只是决定为它制作另一个图像文件并从中创建它。帧率问题主要解决了......我不明白为什么。我以为纹理已经在内存中了?我的代码有什么问题吗?
circleSpriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"spritesheetbase.png"];
//Load Note Animations
for (int i = 0; i < 25; i++)
{
int x = i % 5;
int y = i / 5;
CCSpriteFrame* frame = [[CCSpriteFrame alloc] initWithTexture:circleSpriteSheet.textureAtlas.texture rect:CGRectMake(x * 200, y * 200, 200, 200)];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFrame:frame name:[NSString stringWithFormat:@"noteFrame%d.png", i]];
[frame release];
}
CCSprite *s = [CCSprite spriteWithFile:@"staticRing.png"];
//CCSprite *s = [CCSprite spriteWithSpriteFrameName:@"noteFrame0.png"]; <--- Old way I used to create it
如果有人可以帮助我,我会欠你的!我很困惑。
【问题讨论】:
-
我遇到了帧率问题。我很好奇为什么当纹理和帧已经在内存中时 spriteWithSpriteFrameName 会导致这种滞后。我做精灵表的方式有问题吗?顺便说一句,这是在最新的 Cocos2d 构建中,beta3
-
我认为您只是在缓存东西而不是使用它,然后绘制未缓存的东西。不过我可能错了。
-
当我在更新方法期间实际运行带有动作的动画时,那些缓存的帧正在其他地方使用。我只是将静态帧添加到缓存中并从中获取它。
标签: iphone performance graphics cocos2d-iphone