Laya_TS 设计模式脚本编辑

第一步往需要添加脚本的对象属性中的runtime属性中填写需要添加的包名加类名,并保存发布(保存Ctrl+s,发布Ctrl+F12)

第二步创建脚本,目录如下图

第三步填写代码

/**
* name 
*/
module game{
	export class imageRunTime extends Laya.Image{
		public scaleTime:number = 100;
		constructor(){
			super();
			this.anchorX= this.anchorY = 0.5;
			this.on(Laya.Event.MOUSE_DOWN,this,this.scaleSmal);
			this.on(Laya.Event.MOUSE_UP,this,this.scaleBig);
			//this.on(Laya.Event.MOUSE_OUT,this,this.scaleSmal);
		}
		private scaleSmal():void{
			Laya.Tween.to(this,{scaleX:0.8,scaleY:0.8},this.scaleTime);
		}
		private scaleBig():void{
			Laya.Tween.to(this,{scaleX:1,scaleY:1},this.scaleTime);
		}
	}
}

第四部创建UI视图

import View=laya.ui.View;
import Dialog=laya.ui.Dialog;
module ui.Scenes.test {
    export class TestSceneUI extends View {

        public static  uiView:any ={"type":"View","props":{"y":0,"x":0,"width":1920,"height":640},"child":[{"type":"Image","props":{"y":0,"x":0,"skin":"image/BG.jpg","cacheAs":"bitmap","alpha":1}},{"type":"Image","props":{"y":285,"x":1144,"skin":"image/hero2.png","runtime":"game.imageRunTime"}},{"type":"Image","props":{"y":285,"x":910,"visible":true,"skin":"image/hero1.png","runtime":"game.imageRunTime"}},{"type":"Image","props":{"y":283,"x":726,"skin":"image/hero0.png","runtime":"game.imageRunTime"}},{"type":"Image","props":{"y":289,"x":1031,"skin":"image/hero3.png","runtime":"game.imageRunTime"}}]};
        constructor(){ super()}
        createChildren():void {
        			View.regComponent("game.imageRunTime",game.imageRunTime);

            super.createChildren();

            this.createView(ui.Scenes.test.TestSceneUI.uiView);

        }

    }
}

第五步程序入口处预加载资源

import WebGL = Laya.WebGL;
// 程序入口
class GameMain{
    constructor()
    {
        Laya.init(1920,640, WebGL);//image.atlas
        Laya.loader.load("res/atlas/image.atlas",Laya.Handler.create(this,this.onload));
    }
    private onload():void{
        var bgUipage:ui.Scenes.test.TestSceneUI = new ui.Scenes.test.TestSceneUI();
        //bgUipage.graphics.drawRect(0,0,300,300,"#ff00ff");
        Laya.stage.addChild(bgUipage);
    }
}
new GameMain();

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值