当前位置: 首页>>代码示例>>C++>>正文


C++ BallSprite::runAction方法代码示例

本文整理汇总了C++中BallSprite::runAction方法的典型用法代码示例。如果您正苦于以下问题:C++ BallSprite::runAction方法的具体用法?C++ BallSprite::runAction怎么用?C++ BallSprite::runAction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BallSprite的用法示例。


在下文中一共展示了BallSprite::runAction方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: createAndDropBall

void BallMap::createAndDropBall(int row, int col)
{
    CCSize size = CCDirector::sharedDirector()->getWinSize();
    
    BallSprite *ball = BallSprite::create(row, col);
    
    // create animation
    CCPoint endPosition = positionOfItem(ball);
    CCPoint startPosition = CCPoint(endPosition.x, endPosition.y + size.height / 2);
    ball->setPosition(startPosition);
    float speed = startPosition.y / (2.0 * size.height);
    ball->runAction(CCSequence::create(
                    CCMoveTo::create(speed, endPosition),
                                       CCCallFuncN::create(this, callfuncN_selector(BallMap::setBallNoMoving)),
                                       NULL));
    
    // add to BatchNode
    m_joyPad->get_spriteNode()->addChild(ball);

    m_matrix[row * (int)m_size.width + col] = ball;

}
开发者ID:jindaw,项目名称:learn,代码行数:22,代码来源:BallMap.cpp

示例2: fillVacancies

void BallMap::fillVacancies()
{
    // reset moving direction flag
//    m_movingVertical = true;
    m_isAnimationing = true;
    
    CCSize size = CCDirector::sharedDirector()->getWinSize();
    
    int *colEmptyInfo = (int *)malloc(sizeof(int) * m_size.width);
    memset((void *)colEmptyInfo, 0, sizeof(int) * m_size.width);
    
    // 1. drop exist Ball
    BallSprite *ball = NULL;
    for (int col = 0; col < m_size.width; col++) {
        int removedBallOfCol = 0;
        // from buttom to top
        for (int row = 0; row < m_size.height; row++)
        {
            ball = m_matrix[row * (int)m_size.width + col];
            
            if (NULL == ball)
            {
                removedBallOfCol++;
            }
            else
            {
                if (removedBallOfCol > 0)
                {
                    // evey item have its own drop distance
                    int newRow = row - removedBallOfCol;
                    // switch in matrix
                    m_matrix[newRow * (int)m_size.width + col] = ball;
                    m_matrix[row * (int)m_size.width + col] = NULL;
                    
                    // set the new row to item
                    ball->setRow(newRow);

                    // move to new position
                    CCPoint startPosition = ball->getPosition();
                    CCPoint endPosition = positionOfItem(ball);

                    float speed = (startPosition.y - endPosition.y) / size.height;
                    
                    ball->set_isMoving(true);
//                    ball->stopAllActions();// must stop pre drop action
                    ball->runAction(CCSequence::create(
                                    CCMoveTo::create(speed, endPosition),
                                                       CCCallFuncN::create(this, callfuncN_selector(BallMap::setBallNoMoving)),
                                                       NULL));
                }
            }
        }
        
        // record empty info
        colEmptyInfo[col] = removedBallOfCol;
    }
    
    // 2. create new item and drop down.
    for (int col = 0; col < m_size.width; col++)
    {
        for (int row = m_size.height - colEmptyInfo[col]; row < m_size.height; row++)
        {
            createAndDropBall(row, col);
        }
    }
    
    free(colEmptyInfo);
    colEmptyInfo = NULL;
    
}
开发者ID:jindaw,项目名称:learn,代码行数:70,代码来源:BallMap.cpp

示例3: ccTouchBegan


//.........这里部分代码省略.........
    m_isAnimationing = true;
    m_isTouchEnable = false;
    if (!m_srcBall || !m_destBall)
    {
        m_movingVertical = true;
        return;
    }
    
    CCPoint posOfSrc = m_srcBall->getPosition();
    CCPoint posOfDest = m_destBall->getPosition();
    float time = 0.2;
    
    // 1.swap in matrix
    this->swapBall(m_srcBall, m_destBall);
    
    // 2.check for remove able
    std::list<BallSprite *> colChainListOfFirst;
    getColChain(m_srcBall, colChainListOfFirst);
    
    std::list<BallSprite *> rowChainListOfFirst;
    getRowChain(m_srcBall, rowChainListOfFirst);
    
    std::list<BallSprite *> colChainListOfSecond;
    getColChain(m_destBall, colChainListOfSecond);
    
    std::list<BallSprite *> rowChainListOfSecond;
    getRowChain(m_destBall, rowChainListOfSecond);
    
    if (colChainListOfFirst.size() >= 3
        || rowChainListOfFirst.size() >= 3
        || colChainListOfSecond.size() >= 3
        || rowChainListOfSecond.size() >= 3) {
        // just swap
        m_srcBall->runAction(CCMoveTo::create(time, posOfDest));
        m_destBall->runAction(CCMoveTo::create(time, posOfSrc));
        return;
    }
    
    // 3.no chain, swap back
    this->swapBall(m_srcBall, m_destBall);
    
    m_srcBall->runAction(CCSequence::create(
                                      CCMoveTo::create(time, posOfDest),
                                      CCMoveTo::create(time, posOfSrc),
                                      NULL));
    m_destBall->runAction(CCSequence::create(
                                      CCMoveTo::create(time, posOfSrc),
                                      CCMoveTo::create(time, posOfDest),
                                      NULL));
}
*/
bool BallMap::swapBall(BallSprite* src, BallSprite* dest)
{
    m_srcBall = src;
    m_destBall = dest;
    
    m_matrix[m_srcBall->getRow() * (int)m_size.width + m_srcBall->getCol()] = m_destBall;
    m_matrix[m_destBall->getRow() * (int)m_size.width + m_destBall->getCol()] = m_srcBall;
    
    int tmpRow = m_srcBall->getRow();
    int tmpCol = m_srcBall->getCol();
    
    m_srcBall->setRow(m_destBall->getRow());
    m_srcBall->setCol(m_destBall->getCol());
    
    m_destBall->setRow(tmpRow);
开发者ID:jindaw,项目名称:learn,代码行数:67,代码来源:BallMap.cpp


注:本文中的BallSprite::runAction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。