gpt4 book ai didi

iphone - Cocos2D iPhone - 淡出 Sprite 留下碎片

转载 作者:行者123 更新时间:2023-11-28 17:37:46 25 4
gpt4 key购买 nike

我创建了一个 sprite,在该 sprite 中我有一个这样的标签。

CCLabelTTF *myLabel = [CCLabelTTF 
labelWithString:text
dimensions:CGSizeMake(mySpriteWidth*0.9, mySpriteHeight*0.9)
alignment:UITextAlignmentCenter
fontName:@"Helvetica Neue" fontSize:20.0f];

[myLabel setPosition: CGPointMake((mySpriteWidth/2.0f),(mySpriteHeight/2.0f))];
[mySprite addChild: myLabel];

如您所见,标签是 mySprite 的子项。

然后我使用这个 Action 淡出 Sprite

id fadeOut = [CCFadeOut actionWithDuration:0.4];

Sprite 正确淡出,但标签继续在那里,傲慢地看着我......

这是一个错误还是我遗漏了什么?谢谢


我用来做淡入淡出的代码是这样的:

    CCSequence *sequence =[CCSequence actions:
fadeIn,
[CCDelayTime actionWithDuration:2.5],
fadeOut,
nil];


[mySprite runAction:sequence];
// [myLabel runAction:sequence];

将 Action 添加到标签,使其消失,但随后 Sprite 停留在屏幕上...:(

最佳答案

您应该在淡入淡出完成后移除 Sprite 。如果您不打算再次使用它,则将其删除。或根据需要切换其可见性。

我不能 100% 确定淡出是否会反射(reflect)其内部 View 。它影响从 CRGBAProtocol 继承的对象

CCFadeout reference

这至少应该可以解决您的问题。如果你想让标签淡出,你也可以使用 getChildByTag 访问标签,给它一个淡入淡出的效果。

但是你需要创建一个新的淡入淡出效果,cocos中Actions的实现方式是2个对象可以运行相同的action,后者会。

关于iphone - Cocos2D iPhone - 淡出 Sprite 留下碎片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9286862/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com