quick cocos2dx FilteredSprite c++使用

前端之家收集整理的这篇文章主要介绍了quick cocos2dx FilteredSprite c++使用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
	//测试如何调用 lua 中graySprite的方法
	SpriteFrame*spFrame1 = SpriteFrame::create("dog.png",Rect(0,210,95));

	//Filter*gg = GrayFilter::create(Color4F(0,1,0.5)); //变灰,颜色值变,灰度也变
	//Filter*gg = HueFilter::create(0);//无效果,似乎没有任何用
	//Filter*gg = BrightnessFilter::create(0.6); //效果为:让图片明亮一些,缺点是整张图都变亮了
	//Filter*gg = SaturationFilter::create(1);//更改图片饱和度,0的时候似乎全部变灰,1为正常
	//Filter*gg = ContrastFilter::create(0.5);//更改对比度
	//Filter*gg = ExposureFilter::create(1);//更改曝光度
	//Filter*gg = GammaFilter::create(1);//
	//Filter*gg = HazeFilter::create(0.5,0);// 第一个雾距  第二个 边坡 肯能由于地图山地类型使用
	//Filter*gg = SepiaFilter::create(1);// 分辨率

	/*
	
	local FILTERS = {
	-- colors
	GRAY =			{cc.GrayFilter},-- {r 0.299,g 0.587,b 0.114,a 0.0} or no parameters
	RGB = 			{cc.RGBFilter,3,{1,1}},-- {0.0~1.0,0.0~1.0,0.0~1.0}
	HUE = 			{cc.HueFilter,{0}},-- {-180~ 180} see photoshop
	BRIGHTNESS = 	{cc.BrightnessFilter,-- {-1.0~1.0}
	SATURATION = 	{cc.SaturationFilter,{1}},-- {0.0~2.0}
	CONTRAST = 		{cc.ContrastFilter,-- {0.0~4.0}
	EXPOSURE = 		{cc.ExposureFilter,-- {-10.0,10.0}
	GAMMA = 		{cc.GammaFilter,-- {0.0,3.0}
	HAZE = 			{cc.HazeFilter,2,{0,0}},-- {distance -0.5~0.5,slope -0.5~0.5}
	SEPIA = 		{cc.SepiaFilter},-- {no parameters}
	-- blurs
	GAUSSIAN_VBLUR = 	{cc.GaussianVBlurFilter,-- {pixel}
	GAUSSIAN_HBLUR = 	{cc.GaussianHBlurFilter,-- {pixel}
	ZOOM_BLUR = 		{cc.ZoomBlurFilter,0.5,0.5}},-- {size,centerX,centerY}
	MOTION_BLUR = 		{cc.MotionBlurFilter,angle}
	-- others
	SHARPEN = 		{cc.SharpenFilter,-- {sharpness,amount}
	MASK = 			{cc.MaskFilter,1},-- {DO NOT USE IT}
	DROP_SHADOW = 	{cc.DropShadowFilter,-- {DO NOT USE IT}
	-- custom
	CUSTOM = {cc.CustomFilter,1}
	}

	local MULTI_FILTERS = {
	GAUSSIAN_BLUR = {},}

	*/


	FilteredSpriteWithOne*sp = FilteredSpriteWithOne::createWithSpriteFrame(spFrame1);
	sp->setPosition(Vec2(480,320));
	sp->setFilter(gg);
	this->addChild(sp);

	//参照图
	auto canzhaosp = Sprite::createWithSpriteFrame(spFrame1);
	this->addChild(canzhaosp);
	canzhaosp->setPosition(Vec2(480,220));



需要头文件
#include "filters/cocos2dFilters.h"
USING_NS_CC_EXT;


当然,用到的工程是quick创建的工程

lua 中的写法类似,如下:

    display.newGraySprite("button.png"):align(display.CENTER,display.cx,display.cy):addTo(self)

    local spFrame = cc.SpriteFrame:create("button.png",cc.rect(0,200,200))

    local gfilter = cc.GrayFilter:create(cc.c4f(1,0.5))
    local sp=cc.FilteredSpriteWithOne:createWithSpriteFrame(spFrame); 
    sp:setFilter(gfilter)
    sp:setPosition(display.cx,200)
    self:addChild(sp)
最大的缺点就是一种类型的效果,只能有一种情况存在,为什么设计者不设计成相互独立的呢?

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