ios - CCLabelTTF 在 CCSequence 之后消失

标签 ios cocos2d-iphone label sequence

我需要你的建议。在我的 GameScene 中,我有一个点标签 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);
}

最佳答案

添加 [CCShow Action ] 以确保 Sprite 可见。试试这个:

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 以外的其他奇数)来进行测试。任何一种解决方案都应该有效。

关于ios - CCLabelTTF 在 CCSequence 之后消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10292128/

相关文章:

ios - WebView Xcode 7 空白错误

iOS。更新此项目中的 cocos2d 库后无法运行项目

swift - 快速处理段落

iphone - 动画后cocos2d自动删除 Sprite

java - 为什么我不能在 Java 8 中继续使用带有 Collections#forEach 的标签?

.net - WinForms 中的右对齐标签

ios - swift语言如何在SingleTon类中设置NSDictionary

ios - 在 swift 3 中为货币格式的字符串设置删除线属性文本

objective-c - 如何从 UITableViewCell 推送 View

ios - 有没有办法让整个项目不使用 ARC,同时在新项目上使用 ARC