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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:27:00+00:00 2026-05-30T04:27:00+00:00

Anyone know how I would be able to reduce my following lines of code?

  • 0

Anyone know how I would be able to reduce my following lines of code? I’m still fairly new at objective-c / cocos2D and my following codes look like train wrecks. If it were PHP, I can just create a loop easily to get all these in, but I’m just not familiar enough with obj-c yet to figure it out.

    dinosaur1_c = [CCSprite spriteWithSpriteFrameName:@"dinosaur1-c.png"];
    dinosaur2_c = [CCSprite spriteWithSpriteFrameName:@"dinosaur2-c.png"];
    dinosaur3_c = [CCSprite spriteWithSpriteFrameName:@"dinosaur3-c.png"];
    dinosaur4_c = [CCSprite spriteWithSpriteFrameName:@"dinosaur4-c.png"];
    dinosaur5_c = [CCSprite spriteWithSpriteFrameName:@"dinosaur5-c.png"];
    dinosaur6_c = [CCSprite spriteWithSpriteFrameName:@"dinosaur6-c.png"];
    dinosaur7_c = [CCSprite spriteWithSpriteFrameName:@"dinosaur7-c.png"];
    dinosaur8_c = [CCSprite spriteWithSpriteFrameName:@"dinosaur8-c.png"];
    dinosaur9_c = [CCSprite spriteWithSpriteFrameName:@"dinosaur9-c.png"];
    dinosaur10_c = [CCSprite spriteWithSpriteFrameName:@"dinosaur10-c.png"];
    dinosaur11_c = [CCSprite spriteWithSpriteFrameName:@"dinosaur11-c.png"];

    [sceneSpriteBatchNode addChild:dinosaur1_c];
    [sceneSpriteBatchNode addChild:dinosaur2_c];
    [sceneSpriteBatchNode addChild:dinosaur3_c];
    [sceneSpriteBatchNode addChild:dinosaur4_c];
    [sceneSpriteBatchNode addChild:dinosaur5_c];
    [sceneSpriteBatchNode addChild:dinosaur6_c];
    [sceneSpriteBatchNode addChild:dinosaur7_c];
    [sceneSpriteBatchNode addChild:dinosaur8_c];
    [sceneSpriteBatchNode addChild:dinosaur9_c];
    [sceneSpriteBatchNode addChild:dinosaur10_c];
    [sceneSpriteBatchNode addChild:dinosaur11_c];

Any inputs are greatly appreciated!

  • 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-05-30T04:27:01+00:00Added an answer on May 30, 2026 at 4:27 am

    I recommend managing these objects with an NSMutableArray, like this:

    NSMutableArray *sprites = [[NSMutableArray alloc] init];
    for (int i = 1; i <= 11; i++) {
        id dino = [CCSprite spriteWithSpriteFrameName:[NSString stringWithFormat:@"dinosaur%d-c.png",i]];
        [sprites addObject:dino];
        [sceneSpriteBatchNode addChild:dino];
    }
    
    // Since I don't know what your addChild: method does, the 'sprites' array exists to let you access the objects later, outside of the 'for' loop if desired...
    // So where you would've used dinosaur4_c before, you would instead use [sprites objectAtIndex:4]
    // This also demonstrates how to cast the return value from -objectAtIndex: to a CCSprite *
    CCSprite *certainDino = (CCSprite *)[sprites objectAtIndex:4];
    
    // Then, when done working with the sprites
    [sprites release];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know how I would be able to access the name, url, headline,
Does anyone know what would be the minimum rights I would need to grant
Would anyone know if there are plans or extensions to Visual Studio to allow
Would anyone know what the Win32 equivalent of opendir is (or if it even
Would anyone know how to test for the appearance of a Toast message on
Does anyone know how I would go about changing (transforming) an image based on
I am using double[] instead of NSArray. Would anyone know how to encode it
Does anyone know of a library that would allow me to manipulate Flex DOM
Does anyone know the display formatter that I would need to add to the
Does anyone know why a library initialized within dlopen() would initialize a static variable

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.