layaBox中各类移除&删除&关闭方法小结

2018-09-14  本文已影响0人  一眼就认出你

1、将自身从舞台上移除

let roleLayer: Laya.Sprite=this.roleLayer || new Laya.Sprite();
this.roleLayer.removeSelf();

2、将自身的所以子对象从舞台上移除

let roleLayer: Laya.Sprite=this.roleLayer || new Laya.Sprite();
this.roleLayer.removeChildren(0, this.roleLayer.numChildren - 1);

3、移除定时器

 Laya.timer.clear(this,this.loop);

4、清理对象身上的所有定时器。

cleanAll()  方法

5、从 EventDispatcher 对象中删除指定事件类型的所有侦听器。不传参表示移除所有类型

Laya.stage.offAll();

6、从 EventDispatcher 对象中删除侦听器。(onmouseMove:回调函数)

 Laya.stage.off(Laya.Event.MOUSE_MOVE, this, this.onmouseMove);

7、关闭音效,音乐

     /**
     * 停止声音播放。
         * @param url  声音文件地址。
         */
        static stopSound(url: string): void;
        /**
         * 停止所有声音播放。
         */
        static stopAll(): void;
        /**
         * 停止所有音效,不包括背景音乐。
         */
        static stopAllSound(): void;
        /**
         * 停止背景音乐播放。
         * @param url  声音文件地址。
         */
        static stopMusic(): void;

8、关闭dialog弹出效果

 this.over = this.over || new ui.GameOverUI;
 this.over.close();

9、显示dialog弹出效果

this.over.show();
或者:
this.over.popup();

10、清理graphics上的所有位图

var _sp:Laya.Sprite=new Laya.Sprite()
Laya.stage.addChild(_sp);
//画位图
_sp.graphics.drawLine(0, 0, 100, 100,"#ffffff", 3);
//清除位图
_sp.graphics.clear();
上一篇 下一篇

猜你喜欢

热点阅读