4

我正在使用 cocos2d 制作 BlackJack 游戏,但有一个问题我似乎找不到解决方案。我正在尝试制作这样的初始交易屏幕:

  • 第一张卡片精灵将从屏幕外移动到玩家的手上
  • 第二张卡片精灵将从屏幕外移动到庄家手中
  • 第三 -> 玩家
  • 第四 -> 经销商

为此,我从 Player 和 Dealer 类中调用 drawCard 方法:

[self.player drawCard];
[self.dealer drawCard];
[self.player drawCard];
[self.dealer drawCard];

在drawCard方法中:

-(void) drawCard {
.......
id move = [CCMoveTo actionWithDuration:0.4 position:ccp(x, y)];
        [card.sprite runAction:move];
......
}

我希望第一张卡在第二张卡开始移动之前完成移动到指定位置,但实际上所有 4 张卡几乎同时开始移动。请帮我解决这个问题:(

4

1 回答 1

2

您可以通过 2 种方式做到这一点 1. 使用CCDelayTime2. 使用CCCallBlock

1.使用CCdelayTime

   [self.player drawCard:0]; 
   [self.dealer drawCard:0.5f]; 
   [self.player drawCard:1.0f]; 
   [self.dealer drawCard:1.5f];

    -(void) drawCard:(float)delay
    {
       if(!delay)
       {
          id move = [CCMoveTo actionWithDuration:0.4 position:ccp(x, y)];
          [card.sprite runAction:move];
       }
       else
       {
          id delay    = [CCDelayTime actionWithDuration:delay];
          id move     = [CCMoveTo actionWithDuration:0.4 position:ccp(x, y)];
          id sequence = [CCSequence actions:delay, move, nil];
          [card.sprite runAction:sequence];
       }

    }

2.使用CCCallBlock

    -(void) drawCard:(id)inCard
    {
        mCardIndex++; //in init mCardIndex=0

        id move    = [CCMoveTo actionWithDuration:0.4 position:ccp(x, y)];
        id calBlk  = [CCCallBlock actionWithBlock:^{

                            if(mCardIndex <= TOTAL_CARD)
                            {
                                //here get rightCard
                                [self drawCard:newCard];
                            }
                    }];
        id sequence = [CCSequence actions: move, calBlk,  nil];

        [inCard.sprite runAction:sequence];    
    }
于 2013-03-16T05:07:34.243 回答