180*****237 突然解决了,分享之。
LayaAir2.0中有些东西new没问题,但是运行没效果,调试提示错误“没有构造函数”。
这是因为bin\index.js没有加载对应的库
可以在编辑模式下按F9,在跳出的“项目设置”窗口选择“类库设置”,然后勾选用到的库,点击“确定”自动会添加
比如Laya.tiledMap需要勾选laya.tiledmap.js;
Laya.MovieClip、Laya.Templet需要勾选laya.ani.js
还有个问题,引擎示例中的图集动画Animation,用loadAtlas加载了json文件,动画正常播放了。
但是中间getGraphicBounds()或者getBounds()获取不到动画的宽度高度,
求前辈指点下,谢谢!
代码如下:
//private strAniConfPath:string = "res/fighter/fighter.json"
//private aniFighter:Animation;
this.aniFighter = new Animation();
this.aniFighter.loadAtlas(this.strAniConfPath);
Laya.stage.addChild(this.aniFighter);
this.aniFighter.interval = 100;//30;//设置播放间隔30毫秒
this.aniFighter.index = 1;//当前播放索引
this.aniFighter.play();//播放图集动画
this.aniFighter.loop = false;
//获取动画边界信息,设置锚点
var rectBounds:Rectangle = this.aniFighter.getGraphicBounds();
var rectBounds1:Rectangle = this.aniFighter.getBounds();
//QUESTION=[无法获取图片宽度高度]
this.aniFighter.pivot(512/2,304/2);//rectBounds.width/2,rectBounds.height/2);
this.aniFighter.pos(Laya.stage.width/2,Laya.stage.height/2);