import { Laya } from "Laya" ; import { Sprite } from "laya/display/Sprite" ; import { Stage } from "laya/display/Stage" ; import { ColorFilter } from "laya/filters/ColorFilter" ; import { Texture } from "laya/resource/Texture" ; import { Browser } from "laya/utils/Browser" ; import { Handler } from "laya/utils/Handler" ; import { WebGL } from "laya/webgl/WebGL" ; import { Main } from "./../Main" ; export class Filters_Color { private ApePath : string = "res/apes/monkey2.png" ; private apeTexture : Texture ; Main : typeof Main = null ; constructor ( maincls ) { this . Main = maincls ; Laya . init ( Browser . clientWidth , Browser . clientHeight , WebGL ) ; Laya . stage . alignV = Stage . ALIGN_MIDDLE ; Laya . stage . alignH = Stage . ALIGN_CENTER ; Laya . stage . scaleMode = "showall" ; Laya . stage . bgColor = "#232628" ; Laya . loader . load ( this . ApePath , Handler . create ( this , this . setup ) ) ; } private setup ( e = null ) { this . normalizeApe ( ) ; this . makeRedApe ( ) ; this . grayingApe ( ) ; } private normalizeApe ( ) { var originalApe = this . createApe ( ) ; this . apeTexture = Laya . loader . getRes ( this . ApePath ) ; originalApe . x = ( Laya . stage . width - this . apeTexture . width * 3 ) / 2 ; originalApe . y = ( Laya . stage . height - this . apeTexture . height ) / 2 ; } private makeRedApe ( ) { var redMat = [ 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 ] ; var redFilter = new ColorFilter ( redMat ) ; var redApe = this . createApe ( ) ; redApe . filters = [ redFilter ] ; var firstChild = ( < Sprite > this . Main . box2D . getChildAt ( 0 ) ) ; redApe . x = firstChild . x + this . apeTexture . width ; redApe . y = firstChild . y ; } private grayingApe ( ) { var grayscaleMat = [ 0.3086 , 0.6094 , 0.0820 , 0 , 0 , 0.3086 , 0.6094 , 0.0820 , 0 , 0 , 0.3086 , 0.6094 , 0.0820 , 0 , 0 , 0 , 0 , 0 , 1 , 0 ] ; var grayscaleFilter = new ColorFilter ( grayscaleMat ) ; var grayApe = this . createApe ( ) ; grayApe . filters = [ grayscaleFilter ] ; var secondChild = ( < Sprite > this . Main . box2D . getChildAt ( 1 ) ) ; grayApe . x = secondChild . x + this . apeTexture . width ; grayApe . y = secondChild . y ; } private createApe ( ) { var ape = new Sprite ( ) ; ape . loadImage ( "res/apes/monkey2.png" ) ; this . Main . box2D . addChild ( ape ) ; return ape ; } }