[英]CCLabelTTF disappear after CCSequence
我需要你的建議。 在我的GameScene中,我有一個標記標簽curentPointsLabel 。 要更新,我有一個功能,但是在性能更新后, CurentPoints (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]以確保該精靈是可見的。 嘗試這個:
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以外的其他奇數)來進行測試。 兩種解決方案都應該起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.