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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:33:58+00:00 2026-05-29T06:33:58+00:00

I have a list of about 10 avatars and I am using CCScrollLayer to

  • 0

I have a list of about 10 avatars and I am using CCScrollLayer to display paging. Currently, it only shows 1 avatar per page, and I would much prefer if it showed 3 avatars per page but I am unsure of how to do this.

I’ve attempted to ensure that a new page only generates if there is a MODULUS of 3, but it causes issues because parts of the code needs to be available, such as adding things to the menu.

When I try to use a MODULUS (tied to an if statement) it complains that my menu is out of scope.

My code follows;

// Avatars are generally 70x72
//
GameStateManager *state = [GameStateManager sharedGameStateManager];        
NSLog(@"listOfPlayers.size = %d", [state.listOfPlayers count]);

// Menu of playable characters        
int i=0;

NSMutableArray *pagesArray = [NSMutableArray array];

// --


for (Player *p in state.listOfPlayers) 
{


    // create a blank layer for page
    CCLayer *page = [CCLayer node];
    [page setContentSize:CGSizeMake(200, 100)];

    CCMenu *menu = [CCMenu menuWithItems:nil];
    [menu setContentSize:CGSizeMake(200, 72)];
    [menu alignItemsHorizontallyWithPadding:9.0f];
    [page addChild:menu];


    // --

    NSLog(@"p: %@ (%@) -- locked: %d, playable: %d", p.name, p.fileName, [p.isLocked intValue], [p.isPlayable intValue]);
    //int isLocked    = [p.isLocked intValue];
    int isPlayable  = [p.isPlayable intValue];
    NSString *fileName = [NSString stringWithFormat:@"hold_%@", p.fileName];

    //if ( (isLocked == 0) && (isPlayable == 1) )
    if  (isPlayable == 1) 
    {

        CCSprite *avatarOff = [CCSprite spriteWithSpriteFrameName:fileName];
        CCSprite *avatarOn = [CCSprite spriteWithSpriteFrameName:fileName];

        CCMenuItemSprite *menuItem = [CCMenuItemSprite itemFromNormalSprite:avatarOff selectedSprite:avatarOn target:self selector:nil];
        [menuItem setTag:i];
        [menu addChild:menuItem];

        [pagesArray addObject:page];

        i++;
    }

} // next


// Now create the scroller and pass-in the pages (set widthOffset to 0 for fullscreen pages)
CCScrollLayer *scroller = [[CCScrollLayer alloc] initWithLayers:[NSMutableArray arrayWithArray:pagesArray] widthOffset: 200];


// finally add the scroller to your scene
[self addChild:scroller];

Screenshot follows. It shows 1 avatar per page.

paging avatars

  • 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-29T06:33:59+00:00Added an answer on May 29, 2026 at 6:33 am

    seems to me your are seeing what you are programming. Try

    // Avatars are generally 70x72
    //
    GameStateManager *state = [GameStateManager sharedGameStateManager];        
    NSLog(@"listOfPlayers.size = %d", [state.listOfPlayers count]);
    
    // Menu of playable characters        
    int i=0;
    
    NSMutableArray *pagesArray = [NSMutableArray array];
    
    // --
    
    CCLayer *page=nil;
    CCMenu *menu=nil;
    int avisOnPage=0;
    
    
    for (Player *p in state.listOfPlayers) 
    {
    
      if(0==avisOnPage) {
        // create a blank layer for page
        page = [CCLayer node];
        [page setContentSize:CGSizeMake(200, 100)];
    
        menu = [CCMenu menuWithItems:nil];
        [menu setContentSize:CGSizeMake(200, 72)];
        [menu alignItemsHorizontallyWithPadding:9.0f];
        [page addChild:menu];
        [pagesArray addObject:page];
      } // if new page
    
    // --
    
      NSLog(@"p: %@ (%@) -- locked: %d, playable: %d", p.name, p.fileName, [p.isLocked intValue], [p.isPlayable intValue]);
      //int isLocked    = [p.isLocked intValue];
      int isPlayable  = [p.isPlayable intValue];
      NSString *fileName = [NSString stringWithFormat:@"hold_%@", p.fileName];
    
      //if ( (isLocked == 0) && (isPlayable == 1) )
      if  (isPlayable == 1) 
      {
    
        CCSprite *avatarOff = [CCSprite spriteWithSpriteFrameName:fileName];
        CCSprite *avatarOn = [CCSprite spriteWithSpriteFrameName:fileName];
    
        CCMenuItemSprite *menuItem = [CCMenuItemSprite itemFromNormalSprite:avatarOff selectedSprite:avatarOn target:self selector:nil];
        [menuItem setTag:i];
        [menu addChild:menuItem];
        avisOnPage++;
        i++;
    
        if(3==avisOnPage) avisOnPage=0;
      } // if isPlayable
    } // for player
    
    
    // Now create the scroller and pass-in the pages (set widthOffset to 0 for fullscreen pages)
    CCScrollLayer *scroller = [[CCScrollLayer alloc] initWithLayers:pagesArray widthOffset: 200];
    
    
    // finally add the scroller to your scene
    [self addChild:scroller];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a normal SharePoint list with about 15 columns or so. I
I have a list of about 20k addresses in the US, and I would
I have a list of about 1000 product ids and would like to find
I have a list of about 200,000 IP addresses. I would like to link
I have a List of about 20 items I want to display to the
I have a list containing about 1000 file names to search under a directory
I have a question about list views. I hope someone knows the solution, because
I have a question about list in tcl, what is the correct way to
I have a list: [['18411971', 'kinase_2', 36], ['75910712', 'unnamed...', 160], ... about 60 entries
I have about 10 drop down list controls that get populated. Instead of copying/pasting

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.