LayaBox使用滤镜遇见"Uncaught TypeError: xxx is not a constructor"的问题总结

问题复现
在LayaBox中,滤镜大致可以分为三种:颜色滤镜ColorFilter(可以做一些蒙版)、发光滤镜和阴影滤镜GlowFilter(可以做一些人物、兵器周围的发光效果和阴影效果)、模糊滤镜BlurFilter(可以做模糊效果)。在测试中发现,ColorFilter可以顺利实现效果,但是测试GlowFilter和BlurFilter时控制台总是报出异常,异常如下:LayaBox使用滤镜遇见"Uncaught TypeError: xxx is not a constructor"的问题总结

----------GlowFilter异常Log.png----------

当使用BlurFilter时则会报

Uncaught TypeError: BlurFilter is not a constructor

看到LayaBox官方说滤镜需要在支持WebGL的环境下才能出效果,再加上被网上的一些回答误导,一直以为是chrome没有开启WebGL的原因。
LayaBox使用滤镜遇见"Uncaught TypeError: xxx is not a constructor"的问题总结

----------LayaBox官方文档介绍.png----------

LayaBox使用滤镜遇见"Uncaught TypeError: xxx is not a constructor"的问题总结

----------网友误导解答1.png----------

LayaBox使用滤镜遇见"Uncaught TypeError: xxx is not a constructor"的问题总结

----------网友误导解答2.png----------

于是着手在chrome上开启WebGL功能,网上收了很多教程,各种各样的方法都尝试了,找了一个下午方法,结果还是不行,几乎崩溃。

第二天重新查看这个问题。意识到一个问题,为什么异常是GlowFilter不是构造器呢?要是不支持WebGL的话异常应该是跟WebGL相关的吧。再次网上寻找答案,偶然看到有人说要在编辑模式下引入Filter.js,果然引入后就正常了。

下面贴出引入的方法,如有朋友遇见相同的问题,避免走弯路。

步骤一:在LayaAir IDE中将项目切换到编辑模式

LayaBox使用滤镜遇见"Uncaught TypeError: xxx is not a constructor"的问题总结

----------切换到编辑模式.png----------

步骤二:在编辑模式下按F9打开类库设置,并勾选“laya.filter.js”

LayaBox使用滤镜遇见"Uncaught TypeError: xxx is not a constructor"的问题总结

----------选中“laya.filter.js”并保存.png----------

至此,Filter.js已经作为库进入到了项目之中,重新编译运行,效果就可以出来了。让我们来看一下效果吧 (✪ω✪) (手动滑稽)
LayaBox使用滤镜遇见"Uncaught TypeError: xxx is not a constructor"的问题总结

----------GlowFilter效果图.png----------

说明:图中效果从左到右依次是:无效果、发光效果、阴影效果。
LayaBox使用滤镜遇见"Uncaught TypeError: xxx is not a constructor"的问题总结

----------BlurFilter效果图.png----------

说明:图中效果从左到右依次是:无效果、模糊强度为5的模糊效果。






有没有很炫酷啊?(*^▽^*)