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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:09:10+00:00 2026-06-01T09:09:10+00:00

I am currently developing a card game for the iphone using cocos2d. I am

  • 0

I am currently developing a card game for the iphone using cocos2d. I am currently in need of a tab view with each tab representing a player and his / her set of cards. Currently i have a single view representing just one player. It seems as though cocos2d is not really built do have multiple views, to do this and it would require some serious amount of hacking around with the code. What would be the most efficient way to accomplish this?


can you spot anything obviously wrong here? I created a new class called PlayerController (from apps delegate)
the app delegate calls the scene method, which subsequently populates an array with two “hands” objects and calls initWithPlayerHands (i know it should not be here but i just wanted to get things working first). I have also hard coded moveToPlayerHand to point to element 0

-(CCScene *) scene
{
    // 'scene' is an autorelease object.
    CCScene *scene = [CCScene node];
    // 'layer' is an autorelease object.
    PlayerController *layer = [PlayerController node];

    // add layer as a child to scene
    [scene addChild: layer];

    HelloWorldLayer *layer1 = [[HelloWorldLayer alloc] init];
    HelloWorldLayer *layer2 = [[HelloWorldLayer alloc] init];

    allLayers = [[NSMutableArray alloc] initWithCapacity:6];
    [allLayers addObject:layer1];
    [allLayers addObject:layer2];   
    [self initWithPlayerHands:allLayers];

    // return the scene
    return scene;
}

-(id)initWithPlayerHands:(NSMutableArray *)layers
{
    NSMutableArray *allPlayers;

    if ( (self = [super init]) )    
    {
        currentScreen = 1;
        [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:-1 swallowsTouches:NO];
        [self setIsTouchEnabled:YES];
        scrollWidth = [[CCDirector sharedDirector] winSize].width;
        scrollHeight = [[CCDirector sharedDirector] winSize].height;
        startWidth = scrollWidth;
        startHeight = scrollHeight;

        allPlayers = [[NSMutableArray array] retain];
        int count = [layers count];
        int i = 0;

        for (CCLayer *l in layers)
        {
            l.anchorPoint = ccp(0,0);
            l.position = ccp((i*scrollWidth),0);
            [self addChild:l ];
            i=i+1;
            count-=1;
        }
        totalScreens = i;       
    }       
    return self;
}

-(void) moveToPlayerHand:(int)hand //this represents the layer you want to move to
{
    float dest = /*((currentScreen-1)*scrollHeight);*/ 0;
    id changeHand = [CCEaseBounce actionWithAction:[CCMoveTo actionWithDuration:0.2 position:ccp(0,dest)]];
    [self runAction:changeHand];
    currentScreen = hand;   
}
  • 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-01T09:09:11+00:00Added an answer on June 1, 2026 at 9:09 am

    I have done something similar to this using cocos2d (having different views). I solved the problem by using a scrollIng CCLayer that housed 2 (or more) layers. This scroll layer was part of a scene that had another control layer placed above it (higher z). You can achieve the same thing if you have the different players hands as layers in a scrolling layer and then a separate layer that is higher than the scroller with 2 sprites, or 2 buttons that tell the scrolling layer which of its internal layers to scroll to. The scrolling layer and control layer can communicate using the shared CCScene they are both in.

    Sorry, I guess my answer wasn’t completely clear. These methods should go in a subclass of a CCLayer, so myScrollerLayer:CCLayer should be the interface. The scene should create the array as well as create the scrollerLayer passing the created array to it. So because you have a reference to both the control layer and the scrollerLayer in the scene you can pass messages to each layer.

    Here is the code for the scrolling layer, you should first create your 2 layers that represent the players hand, then you can initiate a new scrolling layer by passing an array of the layers to it:

    -(id) initWithPlayerHands:(NSMutableArray *)layers
    {
    
        if ( (self = [super init]) )
        {
    
            // Make sure the layer accepts touches
            [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:-1 swallowsTouches:NO];
            [self setIsTouchEnabled:YES];
    
            // Set up the starting variables
            currentScreen = 1;
            scrollWidth = [[CCDirector sharedDirector] winSize].width;
            scrollHeight = [[CCDirector sharedDirector] winSize].height;
            startWidth = scrollWidth;
            startHeight = scrollHeight;
    
            allPlayers = [[NSMutableArray array] retain]; //iVar that holds the layers that represent the players hands.
            // Loop through the array and add the screens
            int count = [layers count];
            int i = 0;
            for (CCLayer *l in layers)
            {
    
                l.anchorPoint = ccp(0,0);
                l.position = ccp((i*scrollWidth),0);
                //Add them with inverse levels so that the touches can pass through all of the board layers (This is something I did special for my project, I don't think you have to)
                [self addChild:l z:count];
                [allLayers addObject:l];
                i=i+1;
                count-=1;
    
            }
    
            // Setup a count of the available screens
            totalScreens = i;
    
        }
        return self;
    
    }
    

    And here is how to move to a players hand:

    -(void) moveToPlayerHand:(int)hand //this represents the layer you want to move to
    {
    
        id changeHand = [CCEaseBounce actionWithAction:[CCMoveTo actionWithDuration:0.3 position:ccp(-((page-1)*scrollWidth),0)]];
        [self runAction:changeHand];
        currentScreen = hand;
    
    }
    

    I hope this gets you on the right track, if you want to see how this worked out for me you can check the link in my profile. There is a video in the middle of the page that shows the scrolling.

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

Sidebar

Related Questions

I am currently in the middle of developing a card game using cocos2d. I
Currently developing an application using the newest version of symfony, obtained through PEAR. This
Currently developing a PHP framework and have ran into my first problem. I need
Im currently developing an In-House Enterprise application. I will publish the app using Apple
I was currently developing a desktop application in C# using mono and testing in
I am currently developing a Rails application using a database that was designed before
I'm currently developing a PHP application that's using an Access database as a backend.
Currently developing a connector DLL to HP's Quality Center. I'm using their (insert expelative)
I´m currently developing a web site using Symfony2. On 'dev' environment everything works just
Currently developing my first Native iPhone application, the application is going to be integrating

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.