溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

LayaAir之引入模塊(module)編程方案

發(fā)布時(shí)間:2020-06-24 02:41:14 來(lái)源:網(wǎng)絡(luò) 閱讀:3125 作者:Aonaufly 欄目:開(kāi)發(fā)技術(shù)

LayaAir在引入類等方面確實(shí)沒(méi)有Egret做的好(比較麻煩),本人喜歡模塊,所以給出了在Laya中使用模塊(module)的解決方案.


一 : 關(guān)于MaskDemo.ts的寫法

export module demo{
    export  class MaskDemo{
        private Res : string = null;
        private img : Laya.Sprite = null;
        private cMask : Laya.Sprite = null;
        public constructor(){
            Laya.init(1336,640);
            Laya.stage.bgColor = "#ffffff";
            this.Res = "res/atlas/comp.png";
            Laya.loader.load( this.Res , Laya.Handler.create(this,this.graphicsImg) );
        }
        private graphicsImg() : void{
            this.img = new Laya.Sprite();
            this.img.graphics.drawTexture(Laya.loader.getRes(this.Res), 300 , 100);
            Laya.stage.addChild(this.img);

            // this.cMask = new Laya.Sprite();
            // this.cMask.graphics.drawCircle(80,80,50,"#ff0000");
            // this.cMask.pos(120,50);
            // this.img.mask = this.cMask;
        }
    }
}

注意 :
①,module前面也要以export修飾

二:在Main.ts中引用
Ps : MaskDemo.ts和Main.ts在一個(gè)目錄里面
LayaAir之引入模塊(module)編程方案

import { demo } from "./MaskDemo";

注意: ①{}里面寫入module名稱

使用 : let $mask : demo.MaskDemo = new demo.MaskDemo();

-擴(kuò)展(如果MaskDemo在script里面)
LayaAir之引入模塊(module)編程方案
import { demo } from "./script/MaskDemo";

補(bǔ)充 , 另一種方案
import demo = require("./demo/MaskDemo");
import demo1 = require("./demo/DrawShapes");

運(yùn)用
let $mask : demo.demo.MaskDemo = new demo.demo.MaskDemo();
let $draw : demo1.demo.DrawShapes = new demo1.demo.DrawShapes();

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI