具有大透明背景的CCSpriteBatchNode(cocos2d)

时间:2011-11-28 03:39:44

标签: ios cocos2d-iphone

我写过一堆用于创建视差效果背景的类,其中包含地面,山丘和云。每个对象都被复制一次,这允许我创建一个与地面等无限循环。问题是,使用CCSpriteBatchNode和 12 x PNG 32位纹理与约。大小600px乘200px 将我的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];

1 个答案:

答案 0 :(得分:4)

  

在我的iPhone上运行它给我60 FPS

完美,所以你实际上没有问题!

仅供参考,无论你在模拟器中看到什么帧率,你都不应该对此感到担忧。没有必要浪费时间去思考模拟器的性能。它是无关紧要的,无法比较,对您的应用程序的真实世界性能没有任何意义。