【发布时间】:2011-11-30 02:11:04
【问题描述】:
我编写了一堆类来创建包含地面、山丘和云层的视差效果背景。每个对象都被复制一次,这使我可以用地面等创建一个无限循环。问题是,使用 CCSpriteBatchNode 和 12 x PNG 32 位纹理,大约大小为 600 像素 x 200 像素 将我的 FPS 从 60 降低到 30。我已经读到使用 CCSpriteBatchNode 显示性能有了很大的改进,但我似乎无法复制它们。
http://www.learn-cocos2d.com/2011/09/cocos2d-spritebatch-performance-test/
我怎样才能加快速度?
编辑: 在我的 iPhone 上运行它给我 60 FPS,但它在模拟器中显示 30 FPS:S
这是代码,如果有帮助,它在语法上没有任何问题:
batch = [CCSpriteBatchNode batchNodeWithFile:@"parallax.png"];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"parallax.plist"];
[self addChild:batch];
float screenHeight = [CCUtil screenSize].height;
float screenWidth = [CCUtil screenSize].width;
CCSprite *sky = [CCSprite spriteWithSpriteFrameName:@"sky.png"];
sky.anchorPoint = ccp(0,0);
[batch addChild:sky];
CGPoint speedCloudSlow = ccp(0.08f, 0.002f);
CGPoint speedCloudFast = ccp(0.15f, 0.006f);
CCSprite *clouds1 = [CCSprite spriteWithSpriteFrameName:@"clouds1.png"];
CCSprite *clouds2 = [CCSprite spriteWithSpriteFrameName:@"clouds2.png"];
CCSprite *clouds3 = [CCSprite spriteWithSpriteFrameName:@"clouds3.png"];
CCSprite *clouds4 = [CCSprite spriteWithSpriteFrameName:@"clouds4.png"];
[batch addChild:clouds1];
[batch addChild:clouds2];
[batch addChild:clouds3];
[batch addChild:clouds4];
CCSprite *land1 = [CCSprite spriteWithSpriteFrameName:@"land.png"];
CCSprite *land2 = [CCSprite spriteWithSpriteFrameName:@"land.png"];
CCSprite *landBrown1 = [CCSprite spriteWithSpriteFrameName:@"land_brown.png"];
CCSprite *landBrown2 = [CCSprite spriteWithSpriteFrameName:@"land_brown.png"];
CCSprite *landDark1 = [CCSprite spriteWithSpriteFrameName:@"land_dark.png"];
CCSprite *landDark2 = [CCSprite spriteWithSpriteFrameName:@"land_dark.png"];
CCSprite *ground1 = [CCSprite spriteWithSpriteFrameName:@"ground.png"];
CCSprite *ground2 = [CCSprite spriteWithSpriteFrameName:@"ground.png"];
[batch addChild:land1];
[batch addChild:land2];
[batch addChild:landBrown1];
[batch addChild:landBrown2];
[batch addChild:landDark1];
[batch addChild:landDark2];
[batch addChild:ground1];
[batch addChild:ground2];
【问题讨论】:
-
您在创建自己的类之前尝试过使用 CCParallaxNode 吗?我正在考虑使用它,我想知道您是否遇到了一些问题。
-
不断减少 CCParallaxNode 的 x 或 y 坐标并不是一个非常优雅的解决方案,但主要是我想试一试,并添加我自己的实用方法来添加视差精灵,它会自动在他们离开屏幕后向左/向右移动等。如果你想看看,我会发布课程。
-
正如我所承诺的,我的 CCParallaxScrollNode 类:ak.net84.net/iphone/… 我不会在这个问题中使用它来保持简单。
标签: ios cocos2d-iphone