Cocos2d iphone 关于CCBitmapFontAtlas效果(按一显示)
我正在尝试使用CCBitmapFontAtlas制作效果,以下是我想要的: 字符串表示ABCDEFG正在逐个显示,不会显示每个字符串 直到前一个完全显示 以下是我尝试过的:Cocos2d iphone 关于CCBitmapFontAtlas效果(按一显示),cocos2d-iphone,Cocos2d Iphone,我正在尝试使用CCBitmapFontAtlas制作效果,以下是我想要的: 字符串表示ABCDEFG正在逐个显示,不会显示每个字符串 直到前一个完全显示 以下是我尝试过的: -(id) init { 如果self=[super init]{ label = [CCBitmapFontAtlas bitmapFontAtlasWithString:@"ABC" fntFile:@"bitmapFontTest.fnt"]; [self addChild:label];
-(id) init
{
如果self=[super init]{
label = [CCBitmapFontAtlas bitmapFontAtlasWithString:@"ABC" fntFile:@"bitmapFontTest.fnt"];
[self addChild:label];
CGSize s = [[CCDirector sharedDirector] winSize];
label.position = ccp(s.width/2, s.height/2);
label.anchorPoint = ccp(0.5f, 0.5f);
label.visible = NO; //hide it first
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
}
return self;
}
{
CCSprite AChar=CCSprite[label getChildByTag:0];
CCSprite BChar=CCSprite[label getChildByTag:1];
CCSprite CChar=CCSprite[label getChildByTag:2]
id fade_in = [CCFadeIn actionWithDuration:3];
label.visible = YES;
[AChar runAction:fade_in];
[BChar runAction:fade_in];
[CChar runAction:fade_in];
return YES;
}
效果是一旦我触摸屏幕,ABC就会消失,然后我尝试使用
CallFuncND,在显示当前字符串时调用要淡入的下一个字符串。
但这似乎使事情变得非常复杂
有没有更简单的方法来达到这个效果?
如果您有任何建议,我们将不胜感激。我觉得您的建议是正确的。您可以将每个字母作为一个单独的精灵存储在一个数组中,然后逐个运行它们 调用功能可通过以下方式启动:
[self displayNextSprite:spriteArray nextIndex:0];
其功能是:
// Warning, This assumes you are not passing it an empty array, you may want to put in a check for that
-(void)displayNextSprite:(NSMutableArray*)spriteArray nextIndex:(NSUInteger)nextIndex
{
CCSprite *nextSprite = [spriteArray objectAtIndex:nextIndex];
id action1 = [CCFadeIn actionWithDuration:3];
// or = [CCPropertyAction actionWithDuration:3 key:@"opacity" from:0 to:255];
// The last letter
if(nextIndex == ([spriteArray count] - 1))
{
[nextSprite runAction:action1];
}
else // continue to the next letter
{
id callFunc = [CCCallFunc actionWithTarget:self selector:@selector(displayNextSprite:spriteArray nextIndex:nextIndex+1)];
id sequence = [CCSequence actionOne:action1 two:callFunc];
[nextSprite runAction:sequence];
}
}
// Warning, This assumes you are not passing it an empty array, you may want to put in a check for that
-(void)displayNextSprite:(NSMutableArray*)spriteArray nextIndex:(NSUInteger)nextIndex
{
CCSprite *nextSprite = [spriteArray objectAtIndex:nextIndex];
id action1 = [CCFadeIn actionWithDuration:3];
// or = [CCPropertyAction actionWithDuration:3 key:@"opacity" from:0 to:255];
// The last letter
if(nextIndex == ([spriteArray count] - 1))
{
[nextSprite runAction:action1];
}
else // continue to the next letter
{
id callFunc = [CCCallFunc actionWithTarget:self selector:@selector(displayNextSprite:spriteArray nextIndex:nextIndex+1)];
id sequence = [CCSequence actionOne:action1 two:callFunc];
[nextSprite runAction:sequence];
}
}