LayaAir 拖拽 Sprite 並在屏幕中心放大

onDragEnd(){
		//console.info(this.sp.x+"==="+this.sp.y);
		//console.info(this.sp.pivotX+"==="+this.sp.pivotY);

		let dx:number = 450 - this.sp.x;
		let dy:number = 700 - this.sp.y;
		console.info(dx+"<>"+dy);
		
		this.sp.pivotX += dx;
		this.sp.pivotY += dy;

		this.sp.x += dx;
		this.sp.y += dy;

	}

	onkeydown(){
		if(this.sp.scaleX>1.2){
			this.sp.scale(1,1);
		}else{
			this.sp.scale(1.5,1.5);
		}
	}


private sp:Laya.Sprite;
	private lastDistance: number = 0;

	constructor() {

		Laya.init(900, 1400);
		Laya.loader.load([{ url: "res/atlas/comp.atlas", type: Loader.ATLAS }], Handler.create(this, this.onLoaded));

		Laya.stage.scaleMode = Laya.Stage.SCALE_EXACTFIT;

		Laya.stage.on(Laya.Event.MOUSE_UP, this, this.onMouseUp);
		Laya.stage.on(Laya.Event.KEY_DOWN,this,this.onkeydown);
	}

	onLoaded(){
		this.sp = new Laya.Sprite;
		this.sp.loadImage("comp/map.jpg");
		this.sp.pivot(450,700)
		this.sp.pos(450,700);
		this.sp.on(Laya.Event.MOUSE_DOWN, this, this.onMouseDown);
		this.sp.on(Laya.Event.DRAG_END,this,this.onDragEnd);
		Laya.stage.addChild(this.sp);
		
	}

太晚了 明天有時間的話 編輯此文

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章