2012-04-01 2 views
-1

저는 현재 cocos2d를 사용하여 아이폰 용 카드 게임을 개발 중입니다. 나는 현재 각 탭이 플레이어와 그/그녀의 카드 세트를 나타내는 탭보기가 필요합니다. 현재 저는 단 하나의 플레이어를 나타내는 단일 뷰를 가지고 있습니다. cocos2d가 실제로 빌드되지 않았고 여러 가지보기가있는 것처럼 보입니다. 코드를 해킹 할 때 심각한 양이 필요합니다. 이것을 달성하는 가장 효율적인 방법은 무엇입니까?멀티 플레이어 용 cocos2d 탭보기


여기서 명백히 잘못된 점을 발견 할 수 있습니까? PlayerController라는 새로운 클래스를 만들었습니다. (앱 델리게이트에서) app 대리자가 장면 메서드를 호출합니다.이 메서드는 이후 두 개의 "손"객체로 배열을 채우고 initWithPlayerHands를 호출합니다. 먼저 작업). 또한 열심히 요소 0 I이 사용적인 Cocos2D 비슷한 (다른 견해를 가진)을 수행 한

-(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; 
} 

답변

0

를 가리 키도록 moveToPlayerHand 코딩했다. 나는 2 개 (또는 그 이상)의 레이어를 수용하는 스크롤링 CCLayer를 사용하여이 문제를 해결했다. 이 스크롤 레이어는 위에 다른 컨트롤 레이어가있는 장면의 일부였습니다 (더 높은 z). 스크롤 레이어에서 다른 플레이어가 레이어로 레이어 된 다음 2 개의 스프라이트가있는 스크롤러보다 높은 별도의 레이어 또는 스크롤 레이어에 스크롤 할 내부 레이어를 알려주는 2 개의 버튼이있는 경우에도 동일한 작업을 수행 할 수 있습니다 . 스크롤 레이어와 컨트롤 레이어는 둘 다있는 공유 CCScene을 사용하여 통신 할 수 있습니다.

미안하지만, 내 대답은 분명하지 않았을 것 같습니다. 이러한 메서드는 CCLayer의 하위 클래스에 있어야하므로 myScrollerLayer : CCLayer가 인터페이스 여야합니다. 장면은 배열을 생성하고 생성 된 배열을 scrollerLayer에 전달하여 생성해야합니다. 따라서 장면의 컨트롤 레이어와 scrollerLayer에 대한 참조가 있으므로 각 레이어에 메시지를 전달할 수 있습니다. 여기

가 스크롤 층의 코드, 당신이 먼저 선수의 손을 대표하여 2 층을 생성해야합니다, 당신은 그것에 층의 배열을 전달하여 새로운 화면 이동 층을 시작할 수 있습니다

-(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; 

} 
여기

그리고는 플레이어의 손에 이동하는 방법입니다 :

-(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; 

} 

이 당신이 내 프로필에 링크를 확인하실 수 있습니다 날 위해 어떻게 작동하는지보고 싶다면 나는,이 바른 길에 당신을 얻을 수 있기를 바랍니다. 스크롤을 보여주는 페이지 중간에 비디오가 있습니다.

+0

답장을 보내 주셔서 감사합니다. 내가 찾고있는 코드 일 수도 있습니다. 감사합니다. – godzilla

+0

응답을위한 THanks Tams, 시도해 보았지만 나타납니다. 비록 내가 무엇인지 알 수는 없지만 나는 뭔가 잘못하고있는 것처럼 말입니다. 나는 그것을 하드 코딩하여 항상 첫 번째 "하위보기"즉 게임의 첫 손을 선택합니다. 여기 내 코드 중 일부입니다, 만약 당신이 조언 할 수 있다면 분명히 알 수있는 분명한 실수를 발견 할 수있다 : – godzilla

+0

나는 그것을 정리하기 위해 내 게시물을 편집했다, 나는 이것이 도움이되기를 희망한다! – tams

관련 문제