资源加载
export default class Test extends Laya.Script { constructor() { super(); } private self: any = null; onAwake(){ this.self = this.owner; } onStart(){ //普通 /* Laya.loader.load("gameass/BackgroundMusic.wav",Laya.Handler.create(this,function (){console.log("ok");})); */ //含参 /* Laya.loader.load("gameass/BackgroundMusic.wav",Laya.Handler.create(this,function(sound){console.log("ok",sound);}),null,Laya.Loader.SOUND); */ //多个+进度 /* Laya.loader.load(["gameass/BackgroundMusic.wav","gameass/load.jpg"],Laya.Handler.create(this,function(){console.log("ok");}),Laya.Handler.create(this,function(per){console.log(per);})); */ //获取 /* Laya.loader.load(["gameass/BackgroundMusic.wav","gameass/load.jpg"],Laya.Handler.create(this,function(){ console.log("ok"); let sound = Laya.loader.getRes("gameass/BackgroundMusic.wav"); console.log(sound); }),Laya.Handler.create(this,function(per){console.log(per);})); */ //清理 /* Laya.loader.load(["gameass/BackgroundMusic.wav","gameass/load.jpg"],Laya.Handler.create(this,function(){ console.log("ok"); let sound = Laya.loader.getRes("gameass/BackgroundMusic.wav"); console.log(sound); Laya.loader.clearRes("gameass/BackgroundMusic.wav"); sound = Laya.loader.getRes("gameass/BackgroundMusic.wav"); console.log(sound); }),Laya.Handler.create(this,function(per){console.log(per);})); */ //分组 /* Laya.loader.load(["gameass/BackgroundMusic.wav","gameass/Man_feiji.ogg","gameass/load.jpg"],Laya.Handler.create(this,function(){ console.log("ok"); let sound = Laya.loader.getRes("gameass/BackgroundMusic.wav"); console.log(sound); Laya.loader.setGroup("gameass/BackgroundMusic.wav","sound"); Laya.loader.setGroup("gameass/Man_feiji.ogg","sound"); Laya.loader.clearResByGroup("sound"); sound = Laya.loader.getRes("gameass/BackgroundMusic.wav"); console.log(sound); }),Laya.Handler.create(this,function(per){console.log(per);})); */ //错误处理 /* Laya.loader.load("gameass/BackgroundMusic",Laya.Handler.create(this,function (){console.log("ok");})); Laya.loader.on(Laya.Event.ERROR,this,function(err){ console.log("err:",err); }) */ } }图片切换
export default class Test extends Laya.Script { constructor() { super(); } private self: any = null; onAwake(){ this.self = this.owner; } onStart(){ //this.self.texture = "gameass/background.png"; Laya.loader.load("gameass/background.png",Laya.Handler.create(this,function (bg){ console.log("ok"); this.self.texture = bg; })); } }创建预设
export default class Test extends Laya.Script { constructor() { super(); } onStart(){ Laya.loader.load("gameass/player.prefab",Laya.Handler.create(this,function (player){ console.log("ok"); let node = player.create(); this.owner.addChild(node); node.x = 100; node.y = 100; })); } }图集
图片属性设为默认,F9打开项目设置/图集设置,进行设置。
F12导出代码,结束后可以在图集设置中的路径下找到图集。
图集帧动画
export default class Test extends Laya.Script { constructor() { super(); } private self: any = null; onAwake(){ this.self = this.owner; } onStart(){ Laya.loader.load("res/atlas/gameass/DDZ.atlas",Laya.Handler.create(this,function (at){ console.log("ok"); let anim = new Laya.Animation(); anim.loadAtlas("res/atlas/gameass/DDZ.atlas"); anim.interval = 200; anim.play(0,true); this.owner.addChild(anim); anim.x = 300; anim.y = 300; })); } }