quick-cocos2d-x 学习系列之九filter

前端之家收集整理的这篇文章主要介绍了quick-cocos2d-x 学习系列之九filter前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

quick-cocos2d-x 学习系列之九filter

一看这例子,就感觉适合做电影镜头之类的特效,那种模模糊糊的感觉。

主要定义了一个变量:

MainScene._FILTERS = {

-- custom

{"CUSTOM"},

-- {"CUSTOM",json.encode({frag ="Shaders/example_Flower.fsh",

-- center= {display.cx,display.cy},

-- resolution= {480,320}})},

{{"CUSTOM", "CUSTOM"},

{json.encode({frag = "Shaders/example_Blur.fsh",

shaderName = "blurShader",

resolution = {480,320},

blurRadius = 10,

sampleNum = 5}),

json.encode({frag = "Shaders/example_sepia.fsh",

shaderName = "sepiaShader",})}},

-- colors

{"GRAY",{0.2,0.3,0.5, 0.1}},

{"RGB",{1,0.3}},

{"HUE",{90}},

{"BRIGHTNESS",{0.3}},

{"SATURATION",{0}},

{"CONTRAST",{2}},

{"EXPOSURE",

{"GAMMA",

{"HAZE",{0.1,0.2}},

--{"SEPIA",{}},

-- blurs

{"GAUSSIAN_VBLUR",{7}},

{"GAUSSIAN_HBLUR",

{"ZOOM_BLUR",{4,0.7,0.7}},

{"MOTION_BLUR",{5,135}},

-- others

{"SHARPEN",1}},

{{"GRAY", "GAUSSIAN_VBLUR","GAUSSIAN_HBLUR"},{nil,{10},{10}}},

{{"BRIGHTNESS", "CONTRAST"},{{0.1},{4}}},

{{"HUE", "SATURATION","BRIGHTNESS"},{{240},{1.5},{-0.4}}},

}

包含了里面多个过滤实例。

1.ctor

构造函数调用如下函数

self:_addUI()

self:_createFilters()

self:_showFilter()

2._addUI

创建close按钮,创建向前、向后、重播按钮。

创建clear filter按钮,用于调用函数 _onClearFilter。

创建场景的title.

3._createFilters

设置变量如下:

self._curFilter = 1

self._filterCount = #self._FILTERS

curFilter变量时设置索引,filterCount变量时设置总数。

4._showFilter

函数是本例子的核心。

先判断_filterSprite变量是否存在,存在则设置为nil.

然后通过_curFilter创建当前过滤镜。

通过newFilteredSprite创建带过滤的精灵。

最后创建一个TITLE。

5._onClearFilter

将精灵的滤镜删除

self._filterSprite:clearFilter()

6.newFilteredSprite函数

display.newFilteredSprite()

@H_65_301@display.newFilteredSprite(filename,filters,params)

Create a Filtered Sprite

Parameters

·mixedfilenameAssame a the first parameter for display.newSprite

·mixedfiltersOne ofthe following:

·A Filter name;

·More Filter names(in atable);

·An instance of Filter;

·Some instances of Filter(in atable);

·A Array inclueds someinstances of Filter.

·tableparamsA orsome parameters for Filter.

Returns

·An instance of FilteredSprite

猜你在找的Cocos2d-x相关文章