Cocos2d iphone 如何更改精灵';在一系列动作过程中创建图像
在下面的代码(示例)中,我想在动作序列中更改精灵的图像Cocos2d iphone 如何更改精灵';在一系列动作过程中创建图像,cocos2d-iphone,ccsprite,ccaction,Cocos2d Iphone,Ccsprite,Ccaction,在下面的代码(示例)中,我想在动作序列中更改精灵的图像 spriteActions = [CCRepeatForever actionWithAction: [CCSequence actions: [CCShow action], [CCDelayTime actionWithDuration:1.5], [CCHide act
spriteActions = [CCRepeatForever actionWithAction:
[CCSequence actions:
[CCShow action],
[CCDelayTime actionWithDuration:1.5],
[CCHide action],
[CCDelayTime actionWithDuration:5.0],
[CCShow action],
[CCDelayTime actionWithDuration:3.0],
// I would like to change the sprite image here before completing the remaining actions.
//I want this line here: sprite = [CCSprite SpriteWithFile:@"newSpriteImage.png"];
[CCMoveTo actionWithDuration:2.0 position:newSpritePos],
[CCHide action],
[CCDelayTime actionWithDuration:2.0],
nil]];
[sprite runAction:spriteActions];
谢谢您的帮助。您喜欢这样:
[CCRepeatForever actionWithAction:
[CCSequence actions:
[CCShow action],
[CCDelayTime actionWithDuration:1.5],
[CCHide action],
[CCDelayTime actionWithDuration:5.0],
[CCShow action],
[CCDelayTime actionWithDuration:3.0],
// I would like to change the sprite image here before completing the remaining actions.
[CCCallBlockN actionWithBlock:^(CCNode*node){
CCSprite *spritN = (CCSprite*)node;
//[spritN setDisplayFrame:[cache spriteFrameByName:@"newSpriteImage.png"]]
CCTexture2D* tex = [[CCTextureCache sharedTextureCache] addImage:@"newSpriteImage.png"];
CGSize texSize = tex.contentSize;
CGRect texRect = CGRectMake(0, 0, texSize.width, texSize.height);
CCSpriteFrame* frame = [CCSpriteFrame frameWithTexture:tex rect:texRect];
[spritN setDisplayFrame:frame];
}],
[CCMoveTo actionWithDuration:2.0 position:newSpritePos],
[CCHide action],
[CCDelayTime actionWithDuration:2.0],
nil]];
添加cccallblock或cccallfunc操作