import { Laya } from "Laya" ; import { Sprite } from "laya/display/Sprite" ; import { Stage } from "laya/display/Stage" ; import { Text } from "laya/display/Text" ; import { Event } from "laya/events/Event" ; import { Browser } from "laya/utils/Browser" ; import { WebGL } from "laya/webgl/WebGL" ; import { Main } from "./../Main" ; export class Interaction_FixInteractiveRegion { private logger : Text ; 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" ; this . setup ( ) ; } private setup ( ) { this . buildWorld ( ) ; this . createLogger ( ) ; } private buildWorld ( ) { this . createCoralRect ( ) ; this . createDeepSkyblueRect ( ) ; this . createDarkOrchidRect ( ) ; Laya . stage . name = "暗灰色舞台" ; Laya . stage . on ( Event . MOUSE_DOWN , this , this . onDown ) ; } private createCoralRect ( ) { var coralRect = new Sprite ( ) ; coralRect . graphics . drawRect ( 0 , 0 , Laya . stage . width , Laya . stage . height / 2 , "#FF7F50" ) ; coralRect . name = "珊瑚色容器" ; coralRect . size ( Laya . stage . width , Laya . stage . height / 2 ) ; this . Main . box2D . addChild ( coralRect ) ; coralRect . on ( Event . MOUSE_DOWN , this , this . onDown ) ; } private createDeepSkyblueRect ( ) { var deepSkyblueRect = new Sprite ( ) ; deepSkyblueRect . graphics . drawRect ( 0 , 0 , 100 , 100 , "#00BFFF" ) ; deepSkyblueRect . name = "天蓝色矩形" ; deepSkyblueRect . size ( 100 , 100 ) ; deepSkyblueRect . pos ( 10 , 10 ) ; this . Main . box2D . addChild ( deepSkyblueRect ) ; deepSkyblueRect . on ( Event . MOUSE_DOWN , this , this . onDown ) ; } private createDarkOrchidRect ( ) { var darkOrchidRect = new Sprite ( ) ; darkOrchidRect . name = "暗紫色矩形容器" ; darkOrchidRect . graphics . drawRect ( - 100 , - 100 , 200 , 200 , "#9932CC" ) ; darkOrchidRect . pos ( Laya . stage . width / 2 , Laya . stage . height / 2 ) ; this . Main . box2D . addChild ( darkOrchidRect ) ; darkOrchidRect . mouseThrough = true ; darkOrchidRect . on ( Event . MOUSE_DOWN , this , this . onDown ) ; } private createLogger ( ) { this . logger = new Text ( ) ; this . logger . size ( Laya . stage . width , Laya . stage . height ) ; this . logger . align = 'right' ; this . logger . fontSize = 20 ; this . logger . color = "#FFFFFF" ; this . Main . box2D . addChild ( this . logger ) ; } /**侦听处理方法*/ private onDown ( e = null ) { this . logger . text += "点击 - " + e . target . name + "\n" ; } dispose ( ) { Laya . stage . off ( Event . MOUSE_DOWN , this , this . onDown ) ; } }