Laya_XS
export default class Scene_Battle extends Laya.Script{
playerUnitReady:number;
enemyUnitReady:number;
private playerUnit:Laya.Animation[];
private enemyUnit:Laya.Animation[];
constructor(){
super();
Laya.stage.alignH= Laya.Stage.ALIGN_CENTER;
Laya.stage.alignV = Laya.Stage.ALIGN_MIDDLE;
}
onEnable(){
this.playerUnit = [];
this.enemyUnit = [];
this.playerUnit.push(new Laya.Animation());
this.enemyUnit.push(new Laya.Animation());
this.loadUnit();
}
loadUnit(){
for(let i of this.playerUnit ){
i.loadAtlas("./character/m1.atlas",Laya.Handler.create(this,this.playerUnitLoaded));
}
for(let i of this.enemyUnit){
i.loadAtlas("./character/m1.atlas",Laya.Handler.create(this,this.enemyUnitLoaded));
}
}
playerUnitLoaded(){
for(let i in this.playerUnit){
Laya.Animation.createFrames(this.aniUrls("stand",4),"player"+i+"stand")
//this.playerUnit[i].play(0,true,"player"+i+"stand");
this.playerUnit[i].play();
let bounds = this.playerUnit[i].getGraphicBounds();
this.playerUnit[i].pivot(bounds.width / 2, bounds.height / 2);
this.playerUnit[i].scaleX=300/bounds.width;
this.playerUnit[i].scaleY = 300/bounds.height;
this.playerUnit[i].pos(200,400);
Laya.stage.addChild(this.playerUnit[i]);
}
this.playerUnitReady+=1;
}
enemyUnitLoaded(){
for(let i in this.enemyUnit){
Laya.Animation.createFrames(this.aniUrls("stand",4),"enemy"+i+"stand")
this.enemyUnit[i].play(0,true,"enemy"+i+"stand");
let bounds = this.enemyUnit[i].getGraphicBounds();
this.enemyUnit[i].pivot(bounds.width / 2, bounds.height / 2);
this.enemyUnit[i].scaleX=-300/bounds.width;
this.enemyUnit[i].scaleY = 300/bounds.height;
this.enemyUnit[i].pos(800,400);
Laya.stage.addChild(this.enemyUnit[i]);
}
this.enemyUnitReady+=1;
}
private aniUrls(aniName:string,length:number):any{
var urls:any = [];
for(var i:number = 0;i<length;i++){
//动画资源路径要和动画图集打包前的资源命名对应起来
urls.push("character/m1/"+aniName+i+".png");
}
return urls;
}
}
playerUnitLoaded方法中能得到边界
enemyUnitLoaded方法中得不到边界