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 9139359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:22:38+00:00 2026-06-17T09:22:38+00:00

how in order load music, images, and other stuff to scene with progress bar

  • 0

how in order load music, images, and other stuff to scene with progress bar and move bar smooth..
i guess logic of progress bar is to create new thread – load data and destroy thread
here is my code to load stuff but it’s not work, progress bar appears but not updating value

-(void)s1
{
    [[SimpleAudioEngine sharedEngine] preloadBackgroundMusic:@"game_music.caf"];
}

-(void)s2
{
    [[SimpleAudioEngine sharedEngine] preloadEffect:@"tap.caf"];
}

-(void)startThread
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    EAGLContext *context = [[[EAGLContext alloc]
                               initWithAPI:kEAGLRenderingAPIOpenGLES1
                                sharegroup:[[[[CCDirector sharedDirector] openGLView] context] sharegroup]] autorelease];
    [EAGLContext setCurrentContext:context];

    [self performSelector:@selector(loadBar)];
    //[self schedule:@selector(tick:)];
    [self performSelector:@selector(s1)];                   // uploading file
    [self performSelector:@selector(progressUpdateValue)];  // add 10 value to progress
    [self performSelector:@selector(s2)];                   // uploading file
    [self performSelector:@selector(progressUpdateValue)];  // add 10 value to progress

    [self performSelector:@selector(replaceScene)
                 onThread:[[CCDirector sharedDirector] runningThread]
               withObject:nil
            waitUntilDone:false];
    [pool release];

}

-(void)replaceScene
{
    [[CCDirector sharedDirector]replaceScene:[GameScene node]];
}

-(id)init
{
    self = [super init];
    if (self != nil)
    {
        [NSThread detachNewThreadSelector:@selector(startThread) toTarget:self withObject:nil];
    }
    return self;
}

Thanks in advance.

interface.. there you go..)

@interface LoadScene : CCScene
{
    GPLoadingBar *loadingBar;
    float value;
}
  • 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-17T09:22:39+00:00Added an answer on June 17, 2026 at 9:22 am

    Ok, so you should load resources in background, while updating loadBar in main thread. For the SimpleAudioEngine you really need NSThread, but CCTextureCashe has -addImageAsync method which allow you to load images asynchronously without problems. So your code should look something like this:

    -(void)s1
    {
        [[SimpleAudioEngine sharedEngine] preloadBackgroundMusic:@"game_music.caf"];
    }
    
    -(void)s2
    {
        [[SimpleAudioEngine sharedEngine] preloadEffect:@"tap.caf"];
    }
    
    -(void)startThread
    {
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    
        [self s1];
        loadingBar.value = 0.5;
        [self s2];
    
        [self performSelectorOnMainThread:@selector(replaceScene)
                     withObject:nil
                waitUntilDone:false];
        [pool release];
    
    }
    
    -(void)replaceScene
    {
        [[CCDirector sharedDirector]replaceScene:[GameScene node]];
    }
    
    -(id)init
    {
        self = [super init];
        if (self != nil)
        {
            [self loadBar];
            [NSThread detachNewThreadSelector:@selector(startThread) toTarget:self withObject:nil];
        }
        return self;
    }
    
    -(void) loadingFinished
    {
        [self replaceScene];
    }
    

    Cocos2d has its own updating loop, so you don’t need to create your one for updating loadingBar. It also has a drawing loop, so if you want to dynamically update something on screen you should only set up values for update and not to stop main thread with loading resources

    also, you could use [self s1] instead of [self performSelector:@selector(s1)] because they are identical. Hope that would help

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using a LazyList version in order to load images . It uses external
In order to load image quickly in webpage, we merger many small images into
I am passing the following URL in order to load a report in SSRS.
I need to implement a plugin architecture within c#/.net in order to load custom
I've a web page that renders latex equations using mathjax. In order to load
I've defined the following media queries in order to load different .css files for
In order to load data (from a CSV file) into an Oracle database, I
In order to load a jQuery mobile page using an anchor tag, one just
We are writing hi-load order processing engine. Every cluster node processing some set of
What would need to be done in order to load .ics files with fullcalendar?

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.