关于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
  • 将具有黑色和不透明度 0 的 CCColorLayer 放在场景上会更容易,然后在该图层上运行 CCFadeTo 操作以达到所需的不透明度……然后不需要虚拟 png。


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

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

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

  • 此代码有效,但仅适用于 CCLayer。我在图层上添加了一些sprite,我希望对整个场景产生影响,而不仅仅是图层。请给我整个场景的代码。
  • 只需将 runAction 方法发送到您的场景实例而不是图层。


来源:https://www.codenong.com/8588064/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_8634.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?