Ios CCLabelTTF在CCF序列后消失

Ios CCLabelTTF在CCF序列后消失,ios,cocos2d-iphone,label,sequence,Ios,Cocos2d Iphone,Label,Sequence,我需要你的建议。在我的游戏场景中,我有一个点标签curentPointsLabel。要更新,我有一个函数,但是在性能updateCurentPoints(CCSequence)之后,点标签消失了!为什么? 初始 _curentPointsLabel = [CCLabelTTF labelWithString:@"" dimensions:CGSizeMake(screenSize.width*0.17f, screenSize.height*0.1f) alignment:UITextAlign

我需要你的建议。在我的游戏场景中,我有一个点标签curentPointsLabel。要更新,我有一个函数,但是在性能updateCurentPoints(CCSequence)之后,点标签消失了!为什么?

初始

_curentPointsLabel = [CCLabelTTF labelWithString:@"" dimensions:CGSizeMake(screenSize.width*0.17f, screenSize.height*0.1f) alignment:UITextAlignmentLeft fontName:@"Trebuchet MS" fontSize:15];
_curentPointsLabel.anchorPoint = CGPointMake(1, 1);
_curentPointsLabel.position =  ccp( screenSize.width-screenSize.height/20, screenSize.height-2*screenSize.height/20);
_curentPointsLabel.color = ccc3(0,0,0);
[self addChild:_curentPointsLabel];
当我需要更新点标签时,我会这样做

- (void)updateCurentPoints:(int)points {

    if(_curentPoints+points<0)
        _curentPoints=0;
    else
        _curentPoints=_curentPoints+points;

   // [_curentPointsLabel setString:[NSString stringWithFormat:@"Score: %d",_curentPoints]];

    NSString * valueString=[[[NSString alloc] initWithString:[NSString stringWithFormat:@"Score: %d",_curentPoints]] retain];

    id sequence=[CCSequence actions:
                [CCCallFuncND actionWithTarget: self selector: @selector(setLabelColor:withIndex:) data:(void*)1],
                [CCCallFuncND actionWithTarget: self selector: @selector(setLabelValue:withValue:) data:(NSString*)valueString],
                [CCBlink actionWithDuration:0.5f blinks:2], 
                [CCCallFuncND actionWithTarget: self selector: @selector(setLabelColor:withIndex:) data:(void*)3],

                 nil];

    [_curentPointsLabel runAction:sequence];

    [valueString release];
}

//*******************************************************************
-(void) setLabelValue:(id) sender withValue:(NSString*) value
{   
    CCLabelTTF *label=(CCLabelTTF *)sender;
    NSString * valueString=[[[NSString alloc] initWithString:[NSString stringWithFormat:@"%@",value]] retain];
    [label setString:[NSString stringWithFormat:@"%@",valueString]];
    [valueString release];
}
//*******************************************************************
-(void) setLabelColor:(id) sender withIndex:(int)index
{   
    CCLabelTTF *label=(CCLabelTTF *)sender;

    if(index==0)
        label.color = ccc3(255,255,255);//white
    else if(index==1)
        label.color = ccc3(0,255,0);//green
    else if(index==2)
        label.color = ccc3(255,0,0);//red
    else if(index==3)
        label.color = ccc3(0,0,0);//black
    NSLog(@"color:%i",index);
}
-(void)updateCurentPoints:(int)点{

如果(_curentPoints+points添加[CCShow action]以确保精灵可见。请尝试以下操作:

id sequence=[CCSequence actions:
             [CCCallFuncND actionWithTarget: self selector: @selector(setLabelColor:withIndex:) data:(void*)1],
             [CCCallFuncND actionWithTarget: self selector: @selector(setLabelValue:withValue:) data:(NSString*)valueString],
             [CCBlink actionWithDuration:0.5f blinks:2], 
             [CCShow action],
             [CCCallFuncND actionWithTarget: self selector: @selector(setLabelColor:withIndex:) data:(void*)3],
             nil];

另外,将闪烁次数从2更改为3(或除1之外的其他奇数)进行测试。这两种解决方案中的任何一种都应该有效。

添加[CCShow action]以确保精灵可见。请尝试以下操作:

id sequence=[CCSequence actions:
             [CCCallFuncND actionWithTarget: self selector: @selector(setLabelColor:withIndex:) data:(void*)1],
             [CCCallFuncND actionWithTarget: self selector: @selector(setLabelValue:withValue:) data:(NSString*)valueString],
             [CCBlink actionWithDuration:0.5f blinks:2], 
             [CCShow action],
             [CCCallFuncND actionWithTarget: self selector: @selector(setLabelColor:withIndex:) data:(void*)3],
             nil];

同时将闪烁次数从2改为3(或除1以外的其他奇数)进行测试。这两种解决方案中的任何一种都应该有效。

这与您的原始问题无关,但您的代码中有不必要的
NSString
s初始化和多余的
retain
s。您能看到标签在整个过程中闪烁吗?还是它直接消失了?是的,我能看到,但闪烁完成后标签消失了与您的原始问题无关,但您的代码中有不必要的
NSString
s初始化和多余的
retain
s。您能看到标签在整个过程中闪烁吗?还是它直接消失了?是的,我能看到,但闪烁完成后标签消失了