Iphone 层的过渡效果
在iPhone的cocos2d中,在一个场景中,我如何淡出一层,然后淡入另一层 我的想法是,我有一个屏幕:Iphone 层的过渡效果,iphone,ios,cocos2d-iphone,Iphone,Ios,Cocos2d Iphone,在iPhone的cocos2d中,在一个场景中,我如何淡出一层,然后淡入另一层 我的想法是,我有一个屏幕: 在顶部有分页控件(作为带有切换和选择器的菜单项完成)的一层 屏幕的其余部分填充了显示当前页面内容的另一层 现在,一旦用户单击任何分页控件,我想淡出当前页面的内容层(但保留分页层),并淡入下一页的内容层。这两个层都是相同的,它们根据currentPage变量从plist中拉入数据,因此实际上我需要刷新层 我知道,对于场景,在调用replaceSecene时,可以指定过渡效果。这样做,一切
- 在顶部有分页控件(作为带有切换和选择器的菜单项完成)的一层
- 屏幕的其余部分填充了显示当前页面内容的另一层
currentPage
变量从plist中拉入数据,因此实际上我需要刷新层
我知道,对于场景,在调用replaceSecene
时,可以指定过渡效果。这样做,一切都会成功。但显然,它也会淡出分页控件,这看起来很愚蠢。那么它对层是如何工作的呢?我认为您可以使用让您的CCLayer
s执行s(例如and),这样您就可以实现您想要的
你需要两个“内容层”来分别保存当前页面(A页)和下一页面(B页)。两个内容层的淡入淡出操作结束后,您可以清理页面A。hmmm。。。。使用CCLayerColor(它实现CCRGBAProtocol协议),淡入将传播到其中的任何对象。然后像这样做:
-(void) buttonTouchedCallBack{
id out = [CCFadeTo actionWithDuration:.35 opacity:0];
id callFunc = [CCCallFunc actionWithTarget:self selector:@selector(changeContent)];
id in = [CCFadeTo actionWithDuration:.35 opacity:255];
id enableMenus = [CCCallFunc actionWithTarget:self selector:@selector(layerInView)];
_menu.isTouchEnabled=NO;
[_contentLayer stopAllActions];
[_contentLayer runAction:[CCSequence actions:out,callFunc,in,enableMenus,nil]];
}
-(void) changeContent{
// do your stuff here
}
-(void) layerInView{
_menu.isTouchEnabled=YES;
// and anything else that is appropriate
}
我写了一个小函数,它将使用块来提供与场景过渡相同的淡入淡出效果,但只针对单个层。只需传入要覆盖的层、淡出和淡入的速度、要淡入的颜色以及隐藏层时要执行的块
-(void)fadeLayer:(CCLayer*)layer withOutDuration:(float)outTime inDuration:(float)inTime color:(ccColor3B)color withBlock: (void(^)())block
{
CGSize winSize = [[CCDirector sharedDirector] winSize];
CCLayerColor *toplayer = [CCLayerColor layerWithColor:ccc4(color.r, color.g, color.b, 0) width:winSize.width height:winSize.height];
[layer addChild:toplayer z:INT_MAX];
[toplayer runAction:
[CCSequence actions:
[CCFadeIn actionWithDuration:outTime],
[CCCallBlock actionWithBlock:block],
[CCFadeOut actionWithDuration:inTime],
[CCCallBlockN actionWithBlock:^(CCNode *node) {
[node removeFromParentAndCleanup:YES];
}],
nil]];
}