关于ios:如何在cocos2d iphone的当前运行场景中添加转场效果

How to add transition effect in Current running scene in cocos2d iphone

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

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

1
[[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:1.0f scene:[GamePage scene]]];

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

[self transitionEffect:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
];</wyn></p><hr>
<p>对于场景,与不透明度相关的图层(CCNode 的子类)动作将不起作用。 ! </p>

<p>您可以使用过渡,也可以必须将 CCFadeTo 应用于所有sprite。 </p>

<p>但是如果您选择对所有sprite进行 CCFadeTo,这将需要突然分配大量动作! FPS慢了!! </p>

<p>另一种最佳方法:</p>

<p><center>[wp_ad_camp_2]</center></p><p>告诉你的设计师,制作 1 x 1 像素的方形黑点图像。
最后在 init 方法中添加此代码。 </p>

[cc]   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;

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

1
2
  temp.opacity=0;
  [temp runAction:[CCFadeTo actionWithDuration:1 opacity:255]];   //0 to 255

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

1
2
   temp.opacity=255; // this will cover whole screen with black color
              [temp runAction:[CCFadeTo actionWithDuration:1 opacity:0]]; //255 to 0


你可以在整个 CCLayer 上运行一个动作

1
[self runAction:[CCFadeOut actionWithDuration:0.5f]];

或者您可以使用 CCFadeTo 淡化到所需的不透明度。