一、Sprite:
先加载资源:let url = [
{ url: “res/atlas/image.atlas”, type: Laya.Loader.ATLAS },
];
Laya.loader.load(url, Laya.Handler.create(this, this.init));
在init方法中写下面代码:
1、直接使用Sprite,给Sprite添加贴图
var t = Laya.loader.getRes(“image/yellow2.png”);
var ape = new Sprite();
ape.graphics.drawTexture(t, 0, 0);
this.addChild(ape);
2、使用Image,给Image添加Skin
let img2 = new Laya.Image("image/yellow2.png");
img2.pos(300, 0);
this.addChild(img2);
3、 给Image添加子节点,在给Sprite添加贴图
let img2 = new Laya.Image();
var ape = new Sprite();
var t = Laya.loader.getRes("image/yellow2.png");
ape.graphics.drawTexture(t, 0, 0);
img2.addChild(ape);
img2.pos(300, 0);
this.addChild(img2);