cocos2d 扑克发牌动画

参考文章出处:http://blog.csdn.net/mofiu/article/details/78751138

    cocos2d::Sprite * sp_list[12];
    cocos2d::Sprite* action_poker[48];
    cocos2d::Sprite *m_dispatch_act = cocos2d::create();
    m_dispatch_act->setVisible(true);
    this->addChild(m_dispatch_act);

    //Init
    for (int i = 0; i < 48; ++i)
    {
        action_poker[i] = cocos2d::Sprite::create("poker.png");
        action_poker[i]->setPosition(0, 30);
        action_poker[i]->setRotation(0);
        action_poker[i]->setVisible(true);
        m_dispatch_act->addChild(action_poker[i]);
    }

    //Callback
    cocos2d::CallFunc * callbak = cocos2d::CallFunc::create(
        [&] {
        for (int i = 0; i < 48; ++i)
        {
            action_poker[i]->setVisible(false);
        }

        for (int i = 0; i < 12; ++i)
        {
            auto card = sp_list[i];
            card->setVisible(true);
            card->setPosition(0, -200);
            card->setRotation(0);
            card->setScale(1.2);
            card->setTexture("poker_new.png");
            Action* seq = Sequence::create(DelayTime::create(0.05), MoveTo::create(0.15f, cocos2d::Point(-360 + i * 60, -200)), NULL);
            card->stopAllActions();
            card->runAction(seq);
        }
    });

    int p0 = 0;
    for (int i = 0; i < 48; ++i)
    {
        Action * seq = nullptr;
        float px = 0.0f, py = 0.9f;
        switch (i%4)
        {
        case 0: { sp_list[p0++] = action_poker[i]; px = 0.0f; py = -200.0f; break; }
        case 1: { px = 400.0f; py = 0.0f; break; }
        case 2: { px = 0.0f; py = 250.0f; break; }
        case 3: { px = -400.0f; py = 0.0f; break; }
        }

        seq = Sequence::create(DelayTime::create(i*0.05), MoveTo::create(0.1, cocos2d::Point(px, py)),
            (i == 47) ? callbak : nullptr, NULL);
        action_poker[i]->stopAllActions();
        action_poker[i]->runAction(seq);
    }

你可能感兴趣的:(c++,界面相关,cocos)