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

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

2019年04月03日 18:55:43 悠悠天阁 阅读数 201

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

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

解决办法:
在这里插入图片描述
在这里插入图片描述
勾选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);
}
只要在这里声明以后,代码中就可以使用这些声明的类后者方法了,就不会出现红线了。

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值