COCOS2D,如何使用计时器更改精灵图像,然后重复过程



我有一个更改纹理的精灵(基本上不同的颜色)。我想不立即更改30秒内的纹理。我该如何实现?另外,如何重复该过程?因此,它应该保持蓝色30秒,然后去红色。然后再次重复该过程

   sprite = [CCSprite spriteWithFile:@"blue.png"];
   [sprite setTexture:[[CCTextureCache sharedTextureCache] addImage:@"red.png"] ];

尝试以下:

id delayTime1 = [CCDelayTime actionWithDuration:2.0f];
id calFun1   = [CCCallBlock actionWithBlock:^{
    //HERE SET BLUE TEXTURE..
   sprite.color = ccc3(0,255,0);
}];
id delayTime2 = [CCDelayTime actionWithDuration:2.0f];
id calFun2   = [CCCallBlock actionWithBlock:^{
    //HERE SET RED TEXTURE..
   sprite.color = ccc3(255,0,0);
}];
id sequece = [CCSequence actions:delayTime1, calFun1, delayTime2, calFun2, nil];
id repeate = [CCRepeatForever actionWithAction:sequece];
[sprite runAction:repeate];

相关内容

最新更新