import { Laya } from "Laya" ; import { Sprite } from "laya/display/Sprite" ; import { Stage } from "laya/display/Stage" ; import { Event } from "laya/events/Event" ; import { Browser } from "laya/utils/Browser" ; import { Ease } from "laya/utils/Ease" ; import { Tween } from "laya/utils/Tween" ; import { WebGL } from "laya/webgl/WebGL" ; import { Main } from "./../Main" ; export class Interaction_CustomEvent { static ROTATE : string = "rotate" ; private sp : Sprite ; Main : typeof Main ; 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 . createSprite ( ) ; } private createSprite ( ) { this . sp = new Sprite ( ) ; this . sp . graphics . drawRect ( 0 , 0 , 200 , 200 , "#D2691E" ) ; this . sp . pivot ( 100 , 100 ) ; this . sp . x = Laya . stage . width / 2 ; this . sp . y = Laya . stage . height / 2 ; this . sp . size ( 200 , 200 ) ; this . Main . box2D . addChild ( this . sp ) ; this . sp . on ( Interaction_CustomEvent . ROTATE , this , this . onRotate ) ; this . sp . on ( Event . CLICK , this , this . onSpriteClick ) ; } private onSpriteClick ( e = null ) { var randomAngle = Math . random ( ) * 180 ; this . sp . event ( Interaction_CustomEvent . ROTATE , [ randomAngle ] ) ; } private onRotate ( newAngle ) { Tween . to ( this . sp , { "rotation" : newAngle } , 1000 , Ease . elasticOut ) ; } }