laya.effect.js 10.8 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458

(function(window,document,Laya){
	var __un=Laya.un,__uns=Laya.uns,__static=Laya.static,__class=Laya.class,__getset=Laya.getset,__newvec=Laya.__newvec;

	var BlurFilter=laya.filters.BlurFilter,ColorFilter=laya.filters.ColorFilter,ColorUtils=laya.utils.ColorUtils;
	var Component=laya.components.Component,Ease=laya.utils.Ease,Event=laya.events.Event,GlowFilter=laya.filters.GlowFilter;
	var Handler=laya.utils.Handler,Node=laya.display.Node,Sprite=laya.display.Sprite,Tween=laya.utils.Tween,Utils=laya.utils.Utils;
/**
*...
*@author ww
*/
//class laya.effect.FilterSetterBase
var FilterSetterBase=(function(){
	function FilterSetterBase(){
		this._filter=null;
		this._target=null;
	}

	__class(FilterSetterBase,'laya.effect.FilterSetterBase');
	var __proto=FilterSetterBase.prototype;
	__proto.paramChanged=function(){
		Laya.systemTimer.callLater(this,this.buildFilter);
	}

	__proto.buildFilter=function(){
		if (this._target){
			this.addFilter(this._target);
		}
	}

	__proto.addFilter=function(sprite){
		if (!sprite)return;
		if (!sprite.filters){
			sprite.filters=[this._filter];
			}else{
			var preFilters;
			preFilters=sprite.filters;
			if (preFilters.indexOf(this._filter)< 0){
				preFilters.push(this._filter);
				sprite.filters=Utils.copyArray([],preFilters);
			}
		}
	}

	__proto.removeFilter=function(sprite){
		if (!sprite)return;
		sprite.filters=null;
	}

	__getset(0,__proto,'target',null,function(value){
		if (this._target !=value){
			this._target=value;
			this.paramChanged();
		}
	});

	return FilterSetterBase;
})()


/**
*@Script {name:ButtonEffect}
*@author ww
*/
//class laya.effect.ButtonEffect
var ButtonEffect=(function(){
	function ButtonEffect(){
		this._tar=null;
		this._curState=0;
		this._curTween=null;
		/**
		*effectScale
		*@prop {name:effectScale,type:number,tips:"缩放值",default:"1.5"}
		*/
		this.effectScale=1.5;
		/**
		*tweenTime
		*@prop {name:tweenTime,type:number,tips:"缓动时长",default:"300"}
		*/
		this.tweenTime=300;
		/**
		*effectEase
		*@prop {name:effectEase,type:ease,tips:"效果缓动类型"}
		*/
		this.effectEase=null;
		/**
		*backEase
		*@prop {name:backEase,type:ease,tips:"恢复缓动类型"}
		*/
		this.backEase=null;
	}

	__class(ButtonEffect,'laya.effect.ButtonEffect');
	var __proto=ButtonEffect.prototype;
	__proto.toChangedState=function(){
		this._curState=1;
		if (this._curTween)Tween.clear(this._curTween);
		this._curTween=Tween.to(this._tar,{scaleX:this.effectScale,scaleY:this.effectScale },this.tweenTime,Ease[this.effectEase],Handler.create(this,this.tweenComplete));
	}

	__proto.toInitState=function(){
		if (this._curState==2)return;
		if (this._curTween)Tween.clear(this._curTween);
		this._curState=2;
		this._curTween=Tween.to(this._tar,{scaleX:1,scaleY:1 },this.tweenTime,Ease[this.backEase],Handler.create(this,this.tweenComplete));
	}

	__proto.tweenComplete=function(){
		this._curState=0;
		this._curTween=null;
	}

	/**
	*设置控制对象
	*@param tar
	*/
	__getset(0,__proto,'target',null,function(tar){
		this._tar=tar;
		tar.on(/*laya.events.Event.MOUSE_DOWN*/"mousedown",this,this.toChangedState);
		tar.on(/*laya.events.Event.MOUSE_UP*/"mouseup",this,this.toInitState);
		tar.on(/*laya.events.Event.MOUSE_OUT*/"mouseout",this,this.toInitState);
	});

	return ButtonEffect;
})()


/**
*效果插件基类,基于对象池管理
*/
//class laya.effect.EffectBase extends laya.components.Component
var EffectBase=(function(_super){
	function EffectBase(){
		/**动画持续时间,单位为毫秒*/
		this.duration=1000;
		/**动画延迟时间,单位为毫秒*/
		this.delay=0;
		/**重复次数,默认为播放一次*/
		this.repeat=0;
		/**缓动类型,如果为空,则默认为匀速播放*/
		this.ease=null;
		/**触发事件,如果为空,则创建时触发*/
		this.eventName=null;
		/**效用作用的目标对象,如果为空,则是脚本所在的节点本身*/
		this.target=null;
		/**效果结束后,是否自动移除节点*/
		this.autoDestroyAtComplete=true;
		this._comlete=null;
		this._tween=null;
		EffectBase.__super.call(this);
	}

	__class(EffectBase,'laya.effect.EffectBase',_super);
	var __proto=EffectBase.prototype;
	__proto._onAwake=function(){this.target=this.target|| this.owner;
		if (this.autoDestroyAtComplete)this._comlete=Handler.create(this.target,this.target.destroy,null,false);
		if (this.eventName)this.owner.on(this.eventName,this,this._exeTween);
		else this._exeTween();
	}

	__proto._exeTween=function(){
		this._tween=this._doTween();
		this._tween.repeat=this.repeat;
	}

	__proto._doTween=function(){
		return null;
	}

	__proto.onReset=function(){
		this.duration=1000;
		this.delay=0;
		this.repeat=0;
		this.ease=null;
		this.target=null;
		if (this.eventName){
			this.owner.off(this.eventName,this,this._exeTween);
			this.eventName=null;
		}
		if (this._comlete){
			this._comlete.recover();
			this._comlete=null;
		}
		if (this._tween){
			this._tween.clear();
			this._tween=null;
		}
	}

	return EffectBase;
})(Component)


/**
*...
*@author ww
*/
//class laya.effect.ColorFilterSetter extends laya.effect.FilterSetterBase
var ColorFilterSetter=(function(_super){
	function ColorFilterSetter(){
		/**
		*brightness 亮度,范围:-100~100
		*/
		this._brightness=0;
		/**
		*contrast 对比度,范围:-100~100
		*/
		this._contrast=0;
		/**
		*saturation 饱和度,范围:-100~100
		*/
		this._saturation=0;
		/**
		*hue 色调,范围:-180~180
		*/
		this._hue=0;
		/**
		*red red增量,范围:0~255
		*/
		this._red=0;
		/**
		*green green增量,范围:0~255
		*/
		this._green=0;
		/**
		*blue blue增量,范围:0~255
		*/
		this._blue=0;
		/**
		*alpha alpha增量,范围:0~255
		*/
		this._alpha=0;
		this._color=null;
		ColorFilterSetter.__super.call(this);
		this._filter=new ColorFilter();
	}

	__class(ColorFilterSetter,'laya.effect.ColorFilterSetter',_super);
	var __proto=ColorFilterSetter.prototype;
	__proto.buildFilter=function(){
		this._filter.reset();
		this._filter.color(this.red,this.green,this.blue,this.alpha);
		this._filter.adjustHue(this.hue);
		this._filter.adjustContrast(this.contrast);
		this._filter.adjustBrightness(this.brightness);
		this._filter.adjustSaturation(this.saturation);
		_super.prototype.buildFilter.call(this);
	}

	__getset(0,__proto,'brightness',function(){
		return this._brightness;
		},function(value){
		this._brightness=value;
		this.paramChanged();
	});

	__getset(0,__proto,'alpha',function(){
		return this._alpha;
		},function(value){
		this._alpha=value;
		this.paramChanged();
	});

	__getset(0,__proto,'contrast',function(){
		return this._contrast;
		},function(value){
		this._contrast=value;
		this.paramChanged();
	});

	__getset(0,__proto,'hue',function(){
		return this._hue;
		},function(value){
		this._hue=value;
		this.paramChanged();
	});

	__getset(0,__proto,'saturation',function(){
		return this._saturation;
		},function(value){
		this._saturation=value;
		this.paramChanged();
	});

	__getset(0,__proto,'green',function(){
		return this._green;
		},function(value){
		this._green=value;
		this.paramChanged();
	});

	__getset(0,__proto,'red',function(){
		return this._red;
		},function(value){
		this._red=value;
		this.paramChanged();
	});

	__getset(0,__proto,'blue',function(){
		return this._blue;
		},function(value){
		this._blue=value;
		this.paramChanged();
	});

	__getset(0,__proto,'color',function(){
		return this._color;
		},function(value){
		this._color=value;
		var colorO;
		colorO=ColorUtils.create(value);
		this._red=colorO.arrColor[0] *255;
		this._green=colorO.arrColor[1] *255;
		this._blue=colorO.arrColor[2] *255;
		this.paramChanged();
	});

	return ColorFilterSetter;
})(FilterSetterBase)


/**
*...
*@author ww
*/
//class laya.effect.GlowFilterSetter extends laya.effect.FilterSetterBase
var GlowFilterSetter=(function(_super){
	function GlowFilterSetter(){
		/**
		*滤镜的颜色
		*/
		this._color="#ff0000";
		/**
		*边缘模糊的大小 0~20
		*/
		this._blur=4;
		/**
		*X轴方向的偏移
		*/
		this._offX=6;
		/**
		*Y轴方向的偏移
		*/
		this._offY=6;
		GlowFilterSetter.__super.call(this);
		this._filter=new GlowFilter(this._color);
	}

	__class(GlowFilterSetter,'laya.effect.GlowFilterSetter',_super);
	var __proto=GlowFilterSetter.prototype;
	__proto.buildFilter=function(){
		this._filter=new GlowFilter(this.color,this.blur,this.offX,this.offY);
		_super.prototype.buildFilter.call(this);
	}

	__getset(0,__proto,'blur',function(){
		return this._blur;
		},function(value){
		this._blur=value;
		this.paramChanged();
	});

	__getset(0,__proto,'color',function(){
		return this._color;
		},function(value){
		this._color=value;
		this.paramChanged();
	});

	__getset(0,__proto,'offX',function(){
		return this._offX;
		},function(value){
		this._offX=value;
		this.paramChanged();
	});

	__getset(0,__proto,'offY',function(){
		return this._offY;
		},function(value){
		this._offY=value;
		this.paramChanged();
	});

	return GlowFilterSetter;
})(FilterSetterBase)


/**
*...
*@author ww
*/
//class laya.effect.BlurFilterSetter extends laya.effect.FilterSetterBase
var BlurFilterSetter=(function(_super){
	function BlurFilterSetter(){
		this._strength=4;
		BlurFilterSetter.__super.call(this);
		this._filter=new BlurFilter(this.strength);
	}

	__class(BlurFilterSetter,'laya.effect.BlurFilterSetter',_super);
	var __proto=BlurFilterSetter.prototype;
	__proto.buildFilter=function(){
		this._filter=new BlurFilter(this.strength);
		_super.prototype.buildFilter.call(this);
	}

	__getset(0,__proto,'strength',function(){
		return this._strength;
		},function(value){
		this._strength=value;
	});

	return BlurFilterSetter;
})(FilterSetterBase)


/**
*淡出效果
*/
//class laya.effect.FadeOut extends laya.effect.EffectBase
var FadeOut=(function(_super){
	function FadeOut(){
		FadeOut.__super.call(this);;
	}

	__class(FadeOut,'laya.effect.FadeOut',_super);
	var __proto=FadeOut.prototype;
	__proto._doTween=function(){
		this.target.alpha=1;
		return Tween.to(this.target,{alpha:0},this.duration,Ease[this.ease],this._comlete,this.delay);
	}

	return FadeOut;
})(EffectBase)


/**
*淡入效果
*/
//class laya.effect.FadeIn extends laya.effect.EffectBase
var FadeIn=(function(_super){
	function FadeIn(){
		FadeIn.__super.call(this);;
	}

	__class(FadeIn,'laya.effect.FadeIn',_super);
	var __proto=FadeIn.prototype;
	__proto._doTween=function(){
		this.target.alpha=0;
		return Tween.to(this.target,{alpha:1},this.duration,Ease[this.ease],this._comlete,this.delay);
	}

	return FadeIn;
})(EffectBase)



})(window,document,Laya);