import { Laya } from "Laya" ; import { Animation } from "laya/display/Animation" ; import { Stage } from "laya/display/Stage" ; import { Handler } from "laya/utils/Handler" ; import { Tween } from "laya/utils/Tween" ; import { WebGL } from "laya/webgl/WebGL" ; import { Main } from "./../Main" ; export class BlendMode_Lighter { private phoenixWidth : number = 750 ; private phoenixHeight : number = 550 ; private bgColorTweener : Tween = new Tween ( ) ; private gradientInterval : number = 2000 ; private bgColorChannels : any = { 'r' : 99 , 'g' : 0 , 'b' : 0xFF } ; Main : typeof Main = null ; constructor ( maincls ) { this . Main = maincls ; Laya . init ( this . phoenixWidth * 2 , this . phoenixHeight , WebGL ) ; Laya . stage . alignV = Stage . ALIGN_MIDDLE ; Laya . stage . alignH = Stage . ALIGN_CENTER ; Laya . stage . scaleMode = "showall" ; Laya . stage . bgColor = "#232628" ; this . setup ( ) ; } private setup ( ) { this . createPhoenixes ( ) ; this . evalBgColor ( ) ; Laya . timer . frameLoop ( 1 , this , this . renderBg ) ; } private createPhoenixes ( ) { var scaleFactor = Math . min ( Laya . stage . width / ( this . phoenixWidth * 2 ) , Laya . stage . height / this . phoenixHeight ) ; this . blendedPhoenix = this . createAnimation ( ) ; this . blendedPhoenix . blendMode = "lighter" ; this . blendedPhoenix . scale ( scaleFactor , scaleFactor ) ; this . blendedPhoenix . y = ( Laya . stage . height - this . phoenixHeight * scaleFactor ) / 2 ; this . normalPhoenix = this . createAnimation ( ) ; this . normalPhoenix . scale ( scaleFactor , scaleFactor ) ; this . normalPhoenix . x = this . phoenixWidth * scaleFactor ; this . normalPhoenix . y = ( Laya . stage . height - this . phoenixHeight * scaleFactor ) / 2 ; } normalPhoenix : Animation ; blendedPhoenix : Animation ; private createAnimation ( ) { var frames = [ ] ; for ( var i = 1 ; i <= 25 ; ++ i ) { frames . push ( "res/phoenix/phoenix" + this . preFixNumber ( i , 4 ) + ".jpg" ) ; } var animation = new Animation ( ) ; animation . loadImages ( frames ) ; this . Main . box2D . addChild ( animation ) ; var clips = animation . frames . concat ( ) ; clips = clips . reverse ( ) ; animation . frames = animation . frames . concat ( clips ) ; animation . play ( ) ; return animation ; } private preFixNumber ( num , strLen ) { return ( "0000000000" + num ) . slice ( - strLen ) ; } private evalBgColor ( ) { var color = Math . random ( ) * 0xFFFFFF ; var channels = this . getColorChannals ( color ) ; this . bgColorTweener . to ( this . bgColorChannels , { "r" : channels [ 0 ] , "g" : channels [ 1 ] , "b" : channels [ 2 ] } , this . gradientInterval , null , Handler . create ( this , this . onTweenComplete ) ) ; } private getColorChannals ( color ) { var result = [ ] ; result . push ( color >> 16 ) ; result . push ( color >> 8 & 0xFF ) ; result . push ( color & 0xFF ) ; return result ; } private onTweenComplete ( ) { this . evalBgColor ( ) ; } private renderBg ( ) { this . Main . box2D . graphics . clear ( ) ; this . Main . box2D . graphics . drawRect ( this . blendedPhoenix . x , this . blendedPhoenix . y , this . phoenixWidth , this . phoenixHeight , this . getHexColorString ( ) ) ; } private getHexColorString ( ) { this . bgColorChannels . r = Math . floor ( this . bgColorChannels . r ) ; this . bgColorChannels . g = 0 ; this . bgColorChannels . b = Math . floor ( this . bgColorChannels . b ) ; var r = this . bgColorChannels . r . toString ( 16 ) ; r = r . length == 2 ? r : "0" + r ; var g = this . bgColorChannels . g . toString ( 16 ) ; g = g . length == 2 ? g : "0" + g ; var b = this . bgColorChannels . b . toString ( 16 ) ; b = b . length == 2 ? b : "0" + b ; return "#" + r + g + b ; } dispose ( ) { if ( this . blendedPhoenix == null ) return ; if ( this . normalPhoenix == null ) return ; this . bgColorTweener . clear ( ) ; this . normalPhoenix . stop ( ) ; this . blendedPhoenix . stop ( ) ; Laya . timer . clear ( this , this . renderBg ) ; this . Main . box2D . graphics . clear ( ) ; } }