您的位置:首页 > 移动开发 > Cocos引擎

cocos2d-基本概念(5)-Effects 效果

2010-01-24 23:06 477 查看

Effects 效果

Introduction 介绍

Effects 是一些列特别的动作。相比于改变通常的属性,像透明度,位置,旋转,或者缩放而言,它们修改的一种新的属性,Grid(网格)属性。

一个Grid 属性就好像一个矩阵,是一个网络的线,组成一系列的方块和矩阵。

这些特别的动作把任何一个cocosNode 对象(层,场景,精灵等)变化成Grid,你可以通过它们的顶点来改变它们。

有两种不同的Grid:tiled 和 non-tiled网格,不同的是tiled网格是通过各自tiled组成,而non-tiled是通过顶点组成的。





一个Grid有2个维度,行和列。但是任何一个vertex都有3个维度,xyz。所以你可以建立一个2d或者是3d的效果,不同的是通过tiled-grid-3d 或者是grid-3d。

你可以通过提高增加grid的大小来提高效果的质量,但是效果的速度将会降低。

一个(16,12)大小的grid将会运行的非常快,但是并不会看起来非常的好。(32,24)的将会看起来非常棒,但是在iphone1代中,运行起来不会太快。

How they work 如何工作

Each frame the screen is rendered into a texture (FBO). This texture is transformed into a vertex array and this vertex array (the grid!) is transformed by the grid effects. Finally the vertex array is rendered into the screen.

任何一个屏幕的Frame都会改称成一个Texture(FBO),这个纹理会转换城一个顶点array,这个顶点坐标array是通过grid的效果转换来的。最后,这个顶点数组被显示到屏幕上。

For more information about the internals refer to:

TiledGrid3D and TiledGrid3DAction for tiled grids
Grid3D and Grid3DAction for non-tiled grids
For example, if you have an scene or layer that renders this image:





我们可以把图片转换成以上这样,使用的是Ripple3D action. 就像你砍刀的古怪的图片,踏实用一个32X24的方块,这个grid是一个non-tiled(所有的方块在一起)







以上的是通过一个16X12的方块,并且grid是一个tiled的(所有的方块或者是tiled可以被分开)







3D actions 3D动作

以3D作为它们的后缀命名的,意味着将会产生一个虚拟的3d效果,它们通过改变Grid的z轴。

如果你将要去使用3D动作,你可能会需要用到深度缓存,比较简单的调用方式就是:

// IMPORTANT: Call this function at the very beginning,

//before running your 1st scene

// Create a depth buffer of 24 bits

// These means that openGL z-order will be taken into account

[[Director sharedDirector] setDepthBufferFormat:kDepthBuffer16];


如下的这一段代码,你可能还是需要设着RGBA8888格式像素。这将会使得到透明的效果。

// IMPORTANT: Call this function at the very beginning,

// before running your 1st scene

// Use this pixel format to have transparent buffers

[[Director sharedDirector] setPixelFormat:kRGBA8];

Index of grid effects 效果索引

可用的Grid3DAction

Available
Grid3DAction
actions:

FlipX3D
FlipY3D
Lens3D
Liquid
Ripple3D
Shaky3D
Twirl
Waves
Waves3D
Available
TiledGrid3DAction
actions:

FadeOutBLTiles

FadeOutTRTiles

FadeOutUpTiles

FadeOutDownTiles

JumpTiles3D
ShakyTiles3D

ShatteredTiles3D

ShuffleTiles

SplitCols

SplitRows

TurnOffTiles

WavesTiles3D

Examples 例子

Some examples:

// execute a Waves action on sprite 1

id waves = [Waves actionWithWaves:5 amplitude:20 horizontal:YES vertical:NO

grid:ccg(15,10) duration:5];

[sprite1 runAction: [RepeatForever actionWithAction: waves]];

// and execute a Shaky3D action on sprite 2

id shaky = [Shaky3D actionWithRange:4 shakeZ:NO grid:ccg(15,10) duration:5];

[sprite2 runAction: [RepeatForever actionWithAction: shaky]];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: