点导航左侧第二个,点下面资源,右键打开资源文件夹,把素材扔进去,刷新,点击上方的导出
回到项目,刷新,添加一个动画代码如下
var WebGL = laya.webgl.WebGL;
var Sprite = Laya.Sprite;
Laya.init(SCREEN_WIDTH, SCREEN_HEIGHT, WebGL);
Laya.stage.scaleMode = "showall";
Laya.stage.alignH = "center";
Laya.stage.screenMode = "horizontal";
//_type,_camp,_hp,_speed,_hitRadius,_heroType
Laya.loader.load("res/atlas/role/zhaoyun.atlas",Laya.Handler.create(this,onLoaded),null,Laya.Loader.ATLAS);
function onLoaded(){
Laya.Animation.createFrames(actionNames("role/zhaoyun/zhaoyun_attack_left",4),"zhaoyun_attack_left");
Laya.Animation.createFrames(actionNames("role/zhaoyun/zhaoyun_walk_right",4),"zhaoyun_walk_right");
// Laya.Animation.createFrames(["war/boy_01.png","war/boy_02.png","war/boy_03.png","war/boy_04.png"],"boy");
newRole(200,400,200,"zhaoyun_walk_right")
}
function newRole(x,y,interval,aniName){
role = new Sprite();
Laya.stage.addChild(role);
var body = new Laya.Animation();
body.interval = interval;
//机体添加到容器内
role.addChild(body);
role.pos(x,y)
body.play(0,true,aniName);
//获取动画大小区域
bound = body.getBounds();
//设置机身居中
body.pos(-bound.width/2,-bound.height/2);
}
function actionNames(action,frameNums){
var names = []
for(var i=1;i<=frameNums;i++){
var index = i
if(i<10){index = "0"+i}
names.push(action+"_"+index+".png")
}
return names;
}