Laya2.0微信小游戏开发问题汇总以及解决方案

1.Laya发布时提示index.html not found什么原因?
Laya小游戏发布会引用bin目录下的index.html文件。如果bin目录下没有这个文件,就会出错,游戏就不能正常运行。

解决办法是新建一个微信小游戏工程,拷贝它的bin目录下的index.html文件到当前工程的bin目录下,重新编译程序发布即可。


2.创建一个TextInput然后删掉text里面的内容在设置输入框类型为密码模式,在设置水平对齐方式看看场景会不会卡死?
亲测,Laya2.0.1beta版本已经修复。

Laya官方http://ldc2.layabox.com/layadownload/?type=layaairide-LayaAir IDE 2.0.1beta
已经说明该BUG已经修复。

3.Laya IDE 如何代码格式化?

Windows环境下快捷键: Alt+Shift+F

4.请问下laya2.0的怎么监听animator动画播放完呢

    private anim: Laya.Animation;
    private playAnim():void {
        if (!this.anim) {
            let ani: Laya.Animation = new Laya.Animation();
            ani.loadAnimation("test/TestAni.ani");
            ani.on(Laya.Event.COMPLETE, null, this.animComplete);
            ani.pos(200, 300);
            this.stage.addChild(ani);
            this.anim = ani;
        }
        this.anim.play(0, false);
    }

    private animComplete(res): void {
        console.log('anim complete.', res);
    }

5.Laya.Templet is not a constructor

Laya2.0微信小游戏开发问题汇总以及解决方案

出现这个错误原因在于项目少了一个类库导致的。

解决办法:
Laya2.0微信小游戏开发问题汇总以及解决方案
Laya2.0微信小游戏开发问题汇总以及解决方案
勾选laya.ani.js类库,重新发布编译即可解决。

10 wx方法不能识别,出现红线
问题在于Laya中并不包含微信小程序小游戏的方法,虽然Laya2.0中在项目工程中的libs目录下提供了wx.d.ts文件,里面包含了一个微信提供的方法的说明,但是实际开发中并不全面,有些不如自己直接写呢。

故新建一个MWx.d.ts文件,放在项目工程的libs文件夹下,里面提供微信的方法说明即可。例如:


declare namespace wx {
  function showShareMenu();
  function onShareAppMessage(any);
  function getFileSystemManager();
  let env: any;
  function downloadFile(any);
  function onShow(any);
  function getLaunchOptionsSync();
  function onHide(any);
}

declare class FileSystemManager {
  public access(any);
  public mkdir(any);
  public getSavedFileList(any);
  public removeSavedFile(any);
  saveFile(any);
  copyFile(any);
}

declare class RecorderManager {
  onStart(any);
  onPause(any);
  onResume(any);
  onStop(any);
  onError(any);
  onInterruptionBegin(any);
  onInterruptionEnd(any);
  start(any);
  pause();
  resume();
  stop();
}

declare class StateMachine {
  constructor(any);
}
只要在这里声明以后,代码中就可以使用这些声明的类后者方法了,就不会出现红线了。

利用这个方法,任何其他第三方库里得类或者方法,只要声明在这里,就可以代码中直接使用