如何在cocos2d iphone的当前运行场景中添加过渡效果

day*_*v89 1 iphone cocos2d-iphone ios

如何在cocos2d iphone的当前运行场景中添加过渡效果.意味着我正在制作一个游戏,并且在每个目标之后我想对当前运行场景给出淡入淡出效果或任何类型的效果.

如果我写这个,它将当前场景替换为新场景.但我不想取代场景.

[[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:1.0f scene:[GamePage scene]]];
Run Code Online (Sandbox Code Playgroud)

有没有办法像这样在当前页面上显示效果.我知道这是错的,但我想要这样的东西:

[self transitionEffect:[CCTransitionFade actionWithDuration:0.5]];

小智 5

对于场景,与"不透明度"相关的图层(CCNode的子类)操作将不起作用.!

你可以使用转换,或者必须将CCFadeTo应用于你的所有精灵.

但是如果你选择CCFadeTo给所有精灵,这将需要突然分配大量的动作!FPS减速!!

另一种最佳方法:

告诉您的设计师,制作1 x 1像素的方形黑点图像.最后在init方法中添加此代码.

   CCSprite *temp=[CCSprite spriteWithFile:@"squaredotBlack.png"];
   temp.position=ccp(s.w/2,s.h/2);
   [self addChild:temp z:50000];    //set as most top layer
   temp.scaleX=s.w;
   temp.scaleY=s.h;
    temp.opacity=0;
Run Code Online (Sandbox Code Playgroud)

然后应用,对于整个屏幕的"淡出"过程,增加不透明度.

  temp.opacity=0; 
  [temp runAction:[CCFadeTo actionWithDuration:1 opacity:255]];   //0 to 255 
Run Code Online (Sandbox Code Playgroud)

然后应用,对于整个屏幕的"淡入"过程,降低不透明度.

   temp.opacity=255; // this will cover whole screen with black color
              [temp runAction:[CCFadeTo actionWithDuration:1 opacity:0]]; //255 to 0
Run Code Online (Sandbox Code Playgroud)

  • 将颜色为黑色且不透明度为0的CCColorLayer置于场景上会更容易,然后在该层上运行CCFadeTo动作到所需的不透明度......然后不需要伪png. (3认同)