0

现在,我确实喜欢这个。12 个动画同时移动。

(对不起,我无法上传图片。所以,我做到了。|~| 是一行,这是 3x4 矩阵)

| 1 1 1 |
| 1 1 1 |
| 1 1 1 |
| 1 1 1 |

但是,我想要这样。

ex) 有 12 个面板正向顺序左上角 1, 2, 3, ... , 12

因此,动画移动 1、2、3 个时间段,而不是同一时间。

| 1 2 3 |// 像这样。

我确实搜索了互联网并添加了一些。但是,我不能动那个。我该怎么做。

这是我的代码。

    CCSprite* maker_sh = CCSprite::create("img/marker_sh.jpg") ;
    CCAnimation* sh_ani = CCAnimation::create() ;
    sh_ani -> setDelayPerUnit(0.05) ;

    for(int i = 0 ; i < 24 ; i++)
    {
            int index = i % 5 ;
            int rowIndex = i / 5 ;

            sh_ani -> addSpriteFrameWithTexture(maker_sh -> getTexture(), CCRectMake(index * 120, rowIndex * 120, 120, 120)) ;
    }
    CCAnimate* animate[12] ;
    CCAction* rep[12] ;

    for(int i = 0 ; i < 12 ; i++)
    {
            animate[i] = CCAnimate::create(sh_ani) ;
            rep[i] = CCRepeatForever::create(animate[i]) ;
    }

    int cnt = 0 ;
    CCSprite* test[12] ;
    for(int i = 3 ; i > -1 ; i--)
            for(int j = 0 ; j < 3 ; j++)
            {
                    cnt++ ;
                    test[j + (3 - i) * 3] = CCSprite::createWithTexture(maker_sh -> getTexture(), CCRectMake(0, 0, 120, 120)) ;
                    test[j + (3 - i) * 3] -> setPosition(ccp(j * 125 + 120, i*125 + 75)) ;
                    this -> addChild(test[j + (3 - i) * 3]) ;
                    test[j + (3 - i) * 3] -> runAction(rep[j + (3 - i) * 3]) ;
                    CCLog("%d", cnt) ;
            }
4

1 回答 1

0

不是一个聪明的方法,只是希望这会给你一些帮助:)

CCAnimate* animate[12];
CCAction* rep[12];

float interval = 3.f;//set this value that you need

for (int i=0; i<12; i++)
{
    CCDelayTime* delay = CCDelayTime::create(i*interval);
    animate[i] = CCAnimate::create(sh_ani);
    CCAction* action = CCRepeatForever::create(animate[i]) ;

    rep[i] = CCSequence::create(delay,action);
}
于 2013-05-06T07:21:36.507 回答