Hello all ok here are some code snippets.:
Im my application delegate at the applicationDidFinishLaunching I have.
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// must be called before any othe call to the director
[CCDirector setDirectorType:kCCDirectorTypeDisplayLink];
// Obtain the shared director in order to...
CCDirector *director = [CCDirector sharedDirector];
// Sets landscape mode
[director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
[director setAnimationInterval:1.0/240.0];
// Turn on display FPS
[director setDisplayFPS:NO];
// Turn on multiple touches
EAGLView *glView = [EAGLView viewWithFrame:[window bounds]
pixelFormat:kEAGLColorFormatRGBA8
depthFormat:GL_DEPTH_COMPONENT16_OES
preserveBackbuffer:NO];
[glView setMultipleTouchEnabled:YES];
[[CCDirector sharedDirector] setOpenGLView:glView];
[window addSubview:glView];
[window makeKeyAndVisible];
// Default texture format for PNG/BMP/TIFF/JPEG/GIF images
// It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
// You can change anytime.
//[CCTexture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGBA8888];
[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA4444];
[[CCDirector sharedDirector] runWithScene: [TWSPage4Layer scene]];
So on my scenes I have the following structure, as an example here is one that gives me poor performance.
@implementation TWSPage4Layer
+(id)scene{
CCScene * scene = [CCScene node];
TWSPage4Layer * layer = [TWSPage4Layer node];
[scene addChild:layer];
return scene;
}
-(id)init{
self = [super init];
if(self){
//Configuring the backgorund;
CGSize winSize = [[CCDirector sharedDirector] winSize];
CCSprite * bgImage = [CCSprite spriteWithFile:[(There_Once_was_a_Stone_iPhoneAppDelegate*)[[UIApplication sharedApplication] delegate] nameForResource:@"TWSPage4Bg"]];
bgImage.position = ccp (winSize.width/2,winSize.height/2);
[self addChild:bgImage];
//Configure Bubbles Button menu
bubblesButtom = [CCMenuItemSprite itemFromNormalSprite:[CCSprite spriteWithFile:[(There_Once_was_a_Stone_iPhoneAppDelegate*)[[UIApplication sharedApplication] delegate] nameForResource:@"bubblesButton"]]
selectedSprite:[CCSprite spriteWithFile:[(There_Once_was_a_Stone_iPhoneAppDelegate*)[[UIApplication sharedApplication] delegate] nameForResource:@"bubblesButtonSel"]]
target:self
selector:@selector(bubblesSound)];
CCMenu * menu = [CCMenu menuWithItems:bubblesButtom,nil];
menu.position = ccp(130*[[CCDirector sharedDirector] contentScaleFactor],220*[[CCDirector sharedDirector] contentScaleFactor]);
[self addChild:menu];
//Adding the fish Sprite
fishLayer = [CCLayer node];
fishSprite = [CCSprite spriteWithFile:[(There_Once_was_a_Stone_iPhoneAppDelegate*)[[UIApplication sharedApplication] delegate] nameForResource:@"fish"]];
fishLayer.contentSize = CGSizeMake(fishSprite.contentSize.width, fishSprite.contentSize.height);
fishLayer.position = ccp (60*[[CCDirector sharedDirector] contentScaleFactor],170*[[CCDirector sharedDirector] contentScaleFactor]);
[fishLayer addChild:fishSprite];
[self configureEyeAnimation];
//Adding the text
textSprite = [CCSprite spriteWithFile:[(There_Once_was_a_Stone_iPhoneAppDelegate*)[[UIApplication sharedApplication] delegate] localizedTextImageFileNameForPage:4]];
textSprite.position = ccp (winSize.width/2.0,winSize.height/2.0);//ccp (305,200);
[self addChild:textSprite];
//Configure the bigstopen
angledRock = [CCSprite spriteWithFile:[(There_Once_was_a_Stone_iPhoneAppDelegate*)[[UIApplication sharedApplication] delegate] nameForResource:@"bigStone"]];
angledRock.position = ccp(380*[[CCDirector sharedDirector] contentScaleFactor],90*[[CCDirector sharedDirector] contentScaleFactor]);
//Configure the rolling stone
rollingRock = [CCSprite spriteWithFile:[(There_Once_was_a_Stone_iPhoneAppDelegate*)[[UIApplication sharedApplication] delegate] nameForResource:@"Stone"]];
rollingRock.position = ccp(390*[[CCDirector sharedDirector] contentScaleFactor],210*[[CCDirector sharedDirector] contentScaleFactor]);
[self addChild:angledRock];
[self addChild:rollingRock];
//Preload the bubbles effect
[[SimpleAudioEngine sharedEngine] preloadEffect:@"bubbles.wav"];
[self showBubbles];
//configuring the world
[self configureWorld];
//Set the scheduller
[self schedule:@selector(tick:)];
self.isTouchEnabled = YES;
// Create contact listener
_contactListener = new ContactListener();
_world->SetContactListener(_contactListener);
}
return self;
}
so Basically what I do in all the scenes, is. Create a CCSprite and set is as the background, the background paths are coming from the application delegate which checks what kind of images should load if HD or normal, this is due the bug reported that cocos wasn't loading the @2x images.
then I just add more sprites, some button, ad configure a small animation, which is an eye opening and closing, in 2 frames. Then I configure the physics world and thats it.
Now, if I take the background srpite out, and don't add, it, performance increases.
So here are some FPS.
on iPhone with/without BG image 60 FPS.
on Phone 4 with BGImage 15 FPS
on iPhone 4 without BG image 20-25 FPS
know the biggest image is the bg image which weights around 1.1 MB on 8Bits and 2.2 on 16Bits, I have tried both images and nothing changes.. the rest of CCSprites on the scene , and this particularly wights around 300KB.
I have tried not loading the sound effect but still I get the same results.
Please help me :-(, and let me know if you need to see some more code.
Thx
Gustavo