teddywu package
{
import laya.display.Sprite;
import laya.display.Stage;
import laya.events.Event;
import laya.events.IEventDispatcher;
import laya.utils.Browser;
import laya.utils.Tween;
import laya.webgl.WebGL;
public class testVH
{
protected var _tip:Sprite;
protected var _downFlag:Boolean;
public function testVH()
{
IEventDispatcher;
Config.isAlpha = true;
Config.isAntialias = true;
Laya.init(Browser.width,Browser.height,true);
Laya.stage.scaleMode = Stage.SCALE_FULL;
ChangeSize();
Laya.timer.once(1000,this,function start():void{
Laya.timer.clearAll(this);
Laya.stage.on(Event.RESIZE,this,onResize);
});
}
protected function HengPing(): void {
trace("设置横屏" );
var layaCanvas:Object = Browser.getElementById("layaCanvas");
layaCanvas.width = Browser.width;
layaCanvas.height = Browser.height;
Laya.stage.size(Browser.width,Browser.height);
}
protected function ShuPing(): void {
trace("设置竖屏" );
var layaCanvas:Object = Browser.getElementById("layaCanvas");
layaCanvas.width = Browser.width;
layaCanvas.height = Browser.height;
Laya.stage.size(Browser.width,Browser.height);
}
protected function ChangeSize():void {
if (Browser.width > Browser.height)
HengPing();
else
ShuPing();
if(_tip){
_tip.graphics.clear();
_downFlag = false;
Laya.stage.off(Event.MOUSE_MOVE,this,_moveHandler);
_tip.off(Event.MOUSE_DOWN,this,_downHandler);
_tip.off(Event.MOUSE_UP,this,_upHandler);
_tip.destroy();
}
_tip = new Sprite();
_tip.graphics.drawRect(0,0,100,100,"#FFFFFF");
_tip.size(100,100);
_tip.on(Event.MOUSE_DOWN,this,_downHandler);
_tip.on(Event.MOUSE_UP,this,_upHandler);
Laya.stage.addChild(_tip);
}
protected function onResize():void{
ChangeSize();
}
protected function _downHandler():void{
_downFlag = true;
Laya.stage.on(Event.MOUSE_MOVE,this,_moveHandler);
}
protected function _upHandler():void{
_downFlag = false;
Laya.stage.off(Event.MOUSE_MOVE,this,_moveHandler);
}
protected function _moveHandler():void{
_tip.x = Laya.stage.mouseX;
_tip.y = Laya.stage.mouseY;
}
}
}