zl程序教程

您现在的位置是:首页 >  其它

当前栏目

Cocos2D结合CoreGraphics实现RPG人物中空黑洞吸入效果

实现 效果 结合 cocos2d 人物 黑洞
2023-09-14 08:56:50 时间

大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处.
如果觉得写的不好请多提意见,如果觉得不错请多多支持点赞.谢谢! hopy ;)


Creates a circular area that pushes the image pixels outward, distorting those pixels closest to the circle the most.

Localized Display Name

Hole Distortion

inputImage 

A CIImage object whose display name is Image.

inputCenter 

A CIVector object whose attribute type is CIAttributeTypePosition and whose display name is Center.

Default value: [150 150]

inputRadius 

An NSNumber object whose attribute type is CIAttributeTypeDistance and whose display name is Radius.

Default value: 150.00

以上是滤镜对应的3个参数,很简单:

第一个是输入图片,第二个是黑洞的中心点,最后一个是黑洞的半径.

官方网站还给出了应该显示的效果:

这里写图片描述

好了,下面我们把它放到游戏中去:

//将CGImage转换为CIImage

 CIImage *ciImage = [CIImage imageWithCGImage:_image.CGImage];

 //用过滤器生成新的CIImage

 CIFilter *filter = [CIFilter filterWithName:@"CIHoleDistortion"];

 CIVector *vector = [CIVector vectorWithX:sz.width*_image.scale/2

 Y:sz.height*_image.scale/2];

 [filter setValue:ciImage forKey:@"inputImage"];

 [filter setValue:vector forKey:@"inputCenter"];

 [filter setValue:@(10.0) forKey:@"inputRadius"];

 CIImage *outputImage = [filter outputImage];

以上我们选择RPG人物的中心点为黑洞的中心,且黑洞的半径为10.

编译运行游戏,效果如下:

这里写图片描述

放大一点看一下效果:

这里写图片描述

可以看到上图中的狗狗的肚子里出现了背景草地上一朵小花.

一般来说要想实现该效果,需要自己写OpenGL ES的端点和片段着色器,但是我们通过Cocoa提供的滤镜,避免了较底层的方法,而且实现起来非常简单.


java游戏开发杂谈 - 游戏物体 java游戏开发杂谈 - 游戏物体现实生活中,有很多物体,每个物体的长相、行为都不同。 物体存在于不同的空间内,它只在这个空间内发生作用。 物体没用了,空间就把它剔除,不然既占地方,又需要花精力管理。
Unity 如何制作星空粒子效果? 本经验介绍在Unity游戏引擎中使用Particle System,如何使用自带资源,快速制作星空的粒子特效。工具/原料 Unity 方法/步骤1: 首先,新建一个场景,如果有自己的天空盒资源的话,在Window- Lighting下设置下天空(默认天空盒也不影响演示) 方法/步骤2: 新建一个空对象命名为Star, 为其添加Particle System组件。
本文提供全流程,中文翻译。Chinar坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 —— 高分辨率用户请根据需求调整网页缩放比例)