예제 #1
0
//創建兔子
void GameScene::createRabbits(int randomHole, int type)
{
    ClippingNode *clippingSprite = _clippingNodeArray.at(randomHole);
    Sprite *rabbitSprite = _rabbitMap.at(randomHole);
    
    if(!clippingSprite->getChildren().contains(rabbitSprite))
    {
        //底板(兔兔)
        Sprite *rabbit = Sprite::createWithSpriteFrameName(__String::createWithFormat("download_rabbit_0%d.png",type)->getCString());
        rabbit->setPosition(Vec2(0, -110));
        rabbit->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
        rabbit->setTag(10000000 + type);
        
        auto move = MoveTo::create(0.1f, Vec2(0, -10));
        auto moveBack = MoveTo::create(0.1f, Vec2(0, -200));
        
        //CC_CALLBACK_x可以帶很多參數,可是必須加在this後面,x代表的是程序強迫帶的參數個數
        //ex:CC_CALLBACK_0(cppName::functionName, this, var1, var2...);
        auto animateDone = CallFunc::create(CC_CALLBACK_0(GameScene::actionFinished, this, randomHole) );
        
        ActionInterval* delay = Sequence::create(move, DelayTime::create(1), moveBack, animateDone, NULL);
        rabbit->runAction(delay);
        
        _touchArray[randomHole] = true;   //代表開放第一次點擊
        _rabbitMap.insert(randomHole, rabbit);
        _clippingNodeArray.at(randomHole)->addChild(rabbit);
    }
}