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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:48:52+00:00 2026-06-10T11:48:52+00:00

Hi guys what I am trying to do is to create 6 sprites and

  • 0

Hi guys what I am trying to do is to create 6 sprites and to space them out evenly, I edited some code i got from a book, but am currently stuck at the part where I need to space the sprites out evenly

    [groundNode setPosition:CGPointMake(45, 20)];

where this will stack all 6 sprites on top of each other? How can I make it in such a way it would become something like

    [groundNode setPosition:CGPointMake(45*x, 20)];

where x is the int taken from the for loop. My code is listed at the bottom. Thank you so much!!

-(id)init{
    self = [super init];
    if(self !=nil){
        for(int x=0;x<6;x++){
            [self createGround];
        }   
    }
    return self;
}

-(void) createGround{
    int randomGround = arc4random()%3+1;
    NSString *groundName = [NSString stringWithFormat:@"ground%d.png", randomGround];
    CCSprite *groundSprite = [CCSprite spriteWithFile:groundName];
    [self addChild:groundSprite];
    [self resetGround:groundSprite];
}

-(void) resetGround:(id)node{
    CGSize screenSize =[CCDirector sharedDirector].winSize;
    CCNode *groundNode = (CCNode*)node;
    [groundNode setPosition:CGPointMake(45, 20)];

}
  • 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-10T11:48:53+00:00Added an answer on June 10, 2026 at 11:48 am

    Step one is to build those methods to take an offsetIndex parameter:

    -(void) createGroundWithOffsetIndex: (int) offsetIndex {
    -(void) resetGround: (CCNode *) node withOffsetIndex: (int) offsetIndex {
    

    Then, in createGround, pass it through:

    [self resetGround:groundSprite withOffsetIndex: offsetIndex];
    

    And pass it in from the loop:

    for(int x=0;x<6;x++){
      [self createGroundWithOffsetIndex:x];
    }       
    

    And finally, the bit of code you knew you’d use (inside resetGround:withOffsetIndex:): (note the +1, since offsets (by semantic) start at zero)

    [groundNode setPosition:CGPointMake(45 * offsetIndex+1, 20)];
    

    Some notes:

    • Consider carefully how much passing is necessary here, and try to think of an improved architecture: if you are tiling the same image, perhaps createGround should take a CGRect and be responsible for filling that much area?

    • This is horizontal only; I leave it as an exercise to pass CGPoints (or similar {x,y} struct) as the offsetIndex.

    • Your casting patterns are borderline concerning. Why pass it as an id, then cast it into another local var, when the whole time it came in as yet another type? I’d think that one over…

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

Sidebar

Related Questions

Hey guys - I'm tearing my hair out trying to create a regular expression
Hi Guys i'm trying to let my Screen blink a morse code out using
Hi guys I'm trying the code samples from zend frameworks site on how to
hello guys I am trying to extract all the anchor links from aol but
I am pulling my hair out trying to create an unordered list from an
Hello guys! I have been trying to create a if/else statement code in jQuery
Hello Guys! I have been trying to create a simple sample code for my
Hi guys I'm trying to create cookies but with no success. Here is my
Hi guys i'm trying to create this (image) css border around a div, but
Hi guys i am trying to create one simple make file and execute in

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.