Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8262413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:44:53+00:00 2026-06-08T03:44:53+00:00

I’ve got a problem in my cocos2d game: In the Game’s level layer I’ve

  • 0

I’ve got a problem in my cocos2d game: In the Game’s level layer I’ve 3-5 big sprites for background (1920*640 ~100kb each) ~ 400-500kb in each level. When I switch between menu and various game’s level 4-5 times the game crashes to main IPhone menu

[[CCDirector sharedDirector] replaceScene:transition];

without this big sprites all work perfect!

-(id) init
{
 ....   
    if( (self=[super init])) {
_spriteBGLevel1 = [CCSprite spriteWithFile: [NSString stringWithFormat:@"level_fon_%i_1.png", _currentLevel]]; 
_spriteBGLevel1.anchorPoint = ccp(0, 0);
_spriteBGLevel1.position = CGPointMake(0.0, 0.0); 
[self addChild:_spriteBGLevel1 z:-5];
_spriteBGLevel2 = [CCSprite spriteWithFile: [NSString stringWithFormat:@"level_fon_%i_2.png", _currentLevel]]; 
_spriteBGLevel2.anchorPoint = ccp(0, 0);
_spriteBGLevel2.position = CGPointMake(0.0, 0.0); 
[self addChild:_spriteBGLevel2 z:-5];
_spriteBGLevel3 = [CCSprite spriteWithFile: [NSString stringWithFormat:@"level_fon_%i_3.png", _currentLevel]]; 
_spriteBGLevel3.anchorPoint = ccp(0, 0);
_spriteBGLevel3.position = CGPointMake(0.0, 0.0); 
[self addChild:_spriteBGLevel3 z:-5];        

....


- (void) dealloc
{
....
    _spriteBGLevel1=nil;
    _spriteBGLevel2=nil;
    _spriteBGLevel3=nil;
    [super dealloc];
}

Background.m

#import "Background.h"
#import "GameConfig.h"
#import "XMLReader.h"
#import "CCParallaxNode-Extras.h"
#import "SettingsManager.h"


@implementation Background

@synthesize backgrounds=_backgrounds;
@synthesize backgroundNode=_backgroundNode;

+(id) scene
{
    CCScene *scene = [CCScene node];

    Background *layer = [Background node];

    [scene addChild: layer];

    return scene;
}

-(id) init
{
    if ((self = [super init]))
    {

        CGSize screenSize = [[CCDirector sharedDirector] winSize];

        int currentLevel = [[SettingsManager sharedSettingsManager] getCurrentLevel];

        _backgroundNode = [CCParallaxNode node];
        _backgroundNode.anchorPoint = CGPointMake(0, 0);
        _backgroundNode.position = CGPointMake(0, 0);
        [self addChild:_backgroundNode z:-1];

        NSData *xmlData = [NSData dataWithContentsOfFile:[[NSBundle bundleForClass:[self class]] pathForResource:@"gameScene" ofType:@"xml"]];

        NSError *error = nil;

        NSDictionary *dictionary = [XMLReader dictionaryForXMLData:xmlData error:&error];
        NSDictionary *levelsDict = [dictionary valueForKeyPath:@"levels.level"];
        NSDictionary *levelDict;

        _backgrounds = [[[NSMutableArray alloc] init] retain];

//        [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile: [NSString stringWithFormat:@"level_fon_%i.plist", currentLevel]];


        for (levelDict in levelsDict)
        {

            int idLevel = [[levelDict valueForKeyPath:@"id"] intValue];
            if(idLevel==currentLevel)
            {
                NSDictionary *fonsDict = [levelDict valueForKeyPath:@"background.fon"];

                NSDictionary *fonDict;
                for (fonDict in fonsDict){

                    NSString *name=[fonDict valueForKeyPath:@"name"];
                    int zIndex=[[fonDict valueForKeyPath:@"z"] intValue];
                    float ratio=[[fonDict valueForKeyPath:@"ratio"] floatValue];
                    float offsetx=[[fonDict valueForKeyPath:@"offsetx"] floatValue];
                    float offsety=[[fonDict valueForKeyPath:@"offsety"] floatValue];
                    if(zIndex<0)
                    {    
                    //CCTexture2D* tex = [[CCTextureCache sharedTextureCache] addImage:[NSString stringWithFormat:@"%@", name]];

                    //CCSprite *fon_level_1 = [CCSprite spriteWithSpriteFrameName: [NSString stringWithFormat:@"%@", name]];
                    //CCSprite *fon_level_2 = [CCSprite spriteWithSpriteFrameName: [NSString stringWithFormat:@"%@", name]];
                    //CCSprite *fon_level_1 = [CCSprite spriteWithTexture:tex];
                    //CCSprite *fon_level_2 = [CCSprite spriteWithTexture:tex];

                    fon_level_1 = [CCSprite spriteWithFile:[NSString stringWithFormat:@"%@", name]];
                    fon_level_2 = [CCSprite spriteWithFile:[NSString stringWithFormat:@"%@", name]];

                    fon_level_1.anchorPoint = CGPointMake(0, 0);
                    fon_level_1.position = CGPointMake(0, 0);
                    fon_level_2.anchorPoint = CGPointMake(0, 0);
                    fon_level_2.position = CGPointMake(0, 0);
                    //[_backgroundNode addChild:fon_level_1 z:zIndex parallaxRatio:ccp(ratio, ratio) positionOffset:ccp(offsetx, offsety*screenSize.height)];
                    //[_backgroundNode addChild:fon_level_2 z:zIndex parallaxRatio:ccp(ratio, ratio) positionOffset:ccp(fon_level_1.contentSize.width, offsety*screenSize.height)];
                    [_backgrounds addObject:fon_level_1];
                    [_backgrounds addObject:fon_level_2];

                        fon_level_1=nil;
                        fon_level_2=nil;
                    }    
                }
                break;
            }    
        }

        NSLog(@"count: %d",_backgrounds.count);
        [self scheduleUpdate];
    }
    return self;
}
- (void)scheduleUpdate
{
    [self schedule:@selector(updateBackgroud:)];
}
-(void) updateBackgroud:(ccTime)delta
{
    CGPoint backgroundScrollVel = ccp(-1000, 0);

    _backgroundNode.position = ccpAdd(_backgroundNode.position, ccpMult(backgroundScrollVel, delta));

    for (CCSprite *background in _backgrounds) {
        if (([_backgroundNode convertToWorldSpace:background.position].x+background.contentSize.width/10) < -(background.contentSize.width)) {
            [_backgroundNode incrementOffset:ccp(background.contentSize.width*2,0) forChild:background];
        }
    }
}
- (void) dealloc
{
     _backgroundNode = nil;
    // _backgrounds = nil;
    [_backgrounds removeAllChildren]; 
    [_backgrounds release];
    [super dealloc];
}
@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T03:44:55+00:00Added an answer on June 8, 2026 at 3:44 am

    Well, here’s how I have gone about it:

    • Get as close as possible to a POT texture size. 1920×640 costs you as much memory as a 2048×2048. Maybe you could get your artists to combine the three-five sprites on a single 2048×2848 png, crop with an plist (like for animation).
    • Whenever possible, load textures ‘just in time’, ie before they are required to be visible. If load time became an issue (perceivable lag at an inappropriate game circumstance), convert the texture to .pvr format (faster load), later to .pvr.gz (still faster load time, smaller app download size). PVR will cause some artefacts, so check with graphic people on your project before comiting.
    • Coming out of any level transition (either to some kind of menu or to some cut-scene), cleanup memory used by textures. This means that if the game logic requires returning to the main scene, reload textures just-in-time, during the transition.
    • Last ditch, change the depth setting before loading these large textures (code snippet below). Setting to RGBA444 will save 75% of the memory requirement, BUT, you take a hit on some graphic quality, especially for high saturation images. Once again, if you need to go there, get your graphics people to optimize the images to this depth, so they are satisfied with the result on device.

    cleanup:

    NSLog(@"GESprite<removeUnusedSprites> : before purging all caches");
    [[CCTextureCache sharedTextureCache] dumpCachedTextureInfo];
    [[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];
    [[CCDirector sharedDirector] purgeCachedData];
    NSLog(@"GESprite<removeUnusedSprites> : after purging all caches");
    [[CCTextureCache sharedTextureCache] dumpCachedTextureInfo];
    

    depth (in a CCSprite derivative class, some utility methods), you can do this anywhere anytime:

    +(void) mediumPixelFormat{
        [CCTexture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGBA4444];
    }
    
    +(void) highPixelFormat{
        [CCTexture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGBA8888];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string
I am currently running into a problem where an element is coming back from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.