import { Laya } from "Laya" ; import { Main } from "./../Main" ; 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 { Image } from "laya/ui/Image" ; import { WebGL } from "laya/webgl/WebGL" ; export class SmartScale_T { private modes : any [ ] = [ "noscale" , "exactfit" , "showall" , "noborder" , "full" , "fixedwidth" , "fixedheight" ] ; private index : number = 0 ; private txt : Text ; Main : typeof Main = null ; constructor ( maincls ) { this . Main = maincls ; Laya . init ( 1136 , 640 , WebGL ) ; Laya . stage . scaleMode = "noscale" ; Laya . stage . screenMode = Stage . SCREEN_HORIZONTAL ; Laya . stage . alignH = "center" ; Laya . stage . alignV = "middle" ; var bg = new Image ( ) ; bg . skin = "res/bg.jpg" ; this . Main . box2D . addChild ( bg ) ; this . txt = new Text ( ) ; this . txt . text = "点击我切换适配模式(noscale)" ; this . txt . bold = true ; this . txt . pos ( 0 , 200 ) ; this . txt . fontSize = 30 ; this . txt . on ( "click" , this , this . onTxtClick ) ; this . Main . box2D . addChild ( this . txt ) ; var boy1 = new Image ( ) ; boy1 . skin = "res/cartoonCharacters/1.png" ; boy1 . top = 0 ; boy1 . right = 0 ; boy1 . on ( "click" , this , this . onBoyClick ) ; this . Main . box2D . addChild ( boy1 ) ; var boy2 = new Image ( ) ; boy2 . skin = "res/cartoonCharacters/2.png" ; boy2 . bottom = 0 ; boy2 . right = 0 ; boy2 . on ( "click" , this , this . onBoyClick ) ; this . Main . box2D . addChild ( boy2 ) ; Laya . stage . on ( "click" , this , this . onClick ) ; Laya . stage . on ( "resize" , this , this . onResize ) ; } private onBoyClick ( e ) { var boy = e . target ; if ( boy . scaleX === 1 ) { boy . scale ( 1.2 , 1.2 ) ; } else { boy . scale ( 1 , 1 ) ; } } private onTxtClick ( e ) { e . stopPropagation ( ) ; this . index ++ ; if ( this . index >= this . modes . length ) this . index = 0 ; Laya . stage . scaleMode = this . modes [ this . index ] ; this . txt . text = "点击我切换适配模式" + "(" + this . modes [ this . index ] + ")" ; } private onClick ( e ) { console . log ( "mouse:" , Laya . stage . mouseX , Laya . stage . mouseY ) ; } private onResize ( ) { console . log ( "size:" , Laya . stage . width , Laya . stage . height ) ; } }