[]关于切换图片的问题

class Main{
private plane1:string = "res/plane.png";
private plane2:string = "res/untitled.png";
private img: Laya.Sprite;
private flag: boolean = false;

constructor()
{
Laya.init(1000,800);
this.img = new Laya.Sprite;
this.img.loadImage(this.plane1);
Laya.stage.addChild(this.img);
this.img.graphics.clear();
this.img.loadImage(this.plane2);
Laya.stage.addChild(this.img)
}
}
new Main();
出来的结果是两张图合并到了一起,
于是我再尝试
constructor()
{
Laya.init(1000,800);
this.img = new Laya.Sprite;
this.img.loadImage(this.plane1);
this.img.graphics.clear();
Laya.stage.addChild(this.img);
}
发现graphics.clear没有清除掉第一张图片
请问这是怎么回事呢?
已邀请:

Laya_XS

赞同来自:

应该是你在clear的时候图片还没有加载后完导致的,你可以在loadimage的回调函数里做你的清理操作就可以有效果了,图片切换还是建议用image组件,对你来说也简单。

要回复问题请先

商务合作
商务合作