Effects are a special kind of action. Instead of modifying normal properties like opacity, position, rotation, or scale, they modify a new kind of property: the grid property.
A grid property is like a matrix. It is a network of lines that cross each other to form a series of squares or rectangles.
These special actions render any cocos2d-x Node object (Layer, Scene, Sprite, etc.) into the grid and you can transform the grid by moving its vertices.
There are 2 kind of grids: tiled grids and non-tiled grids. The difference is that the tiled grid is composed of individual tiles while the non-tiled grid is composed of vertices.
The following is an example of Ripple3D action, who uses a Grid3D (non-tiled) grid:
and the following is an example of FadeOutTR action, who uses a TiledGrid3D (tiled) grid:
How do I use them ?¶
Like any other action, it is executed by the
// Create an sprite Sprite* grossini = Sprite::create("grossini.png"); grossini->runAction(Liquid::create(2, Size(32,24), 1, 20));
-- Create an sprite local grossini = cc.Sprite:create("grossini.png") grossini:runAction(cc.Liquid:create(2, cc.size(32,24), 4, 20))
Liquid, like any other grid action, receives the grid parameter. You can adjust the quality of the effect by increasing the size of the grid. But it also implies less FPS.
The Effects are
IntervalAction actions so you can treat them like any other action. eg:
// create a Lens3D action ActionInterval* lens = Lens3D::create(10, Size(32,24), Vec2(100,180), 150)； // create a Waved3D action ActionInterval* waves = Waves3D::create(10, Size(15,10), 18, 15); // create a sequence an repeat it forever grossini->runAction(RepeatForever::create((Sequence*)Sequence::create(waves, lens, NULL ) ) );
-- create a Lens3D action local lens = cc.Lens3D:create(10, cc.size(32,24), cc.p(100,180), 150) -- create a Waved3D action local waves = cc.Waves3D:create(10, cc.size(15,10), 18, 15) --create a sequence an repeat it forever grossini:runAction(cc.RepeatForever:create(cc.Sequence:create(waves, lens)))
The following are Grid3D (non-tiled) actions in v2.1.0:
The following are TiledGrid3D (tiled) actions:
cocos2d-iphone Introduction to cocos2d’s effects