Commit cae7f496 authored by 李维's avatar 李维

修复切换时偶现的背景消失的问题

parent c5d5ac15
......@@ -198,7 +198,7 @@ export default class NewClass extends cc.Component {
initCustomBg(bg_image_url) {
console.log("Iniit", bg_image_url)
if(!bg_image_url) {
if (!bg_image_url) {
// 没有背景图 还原默认图
cc.find("bg/bg_default", this.node).active = true;
cc.find("bg/bg", this.node).active = false;
......@@ -206,12 +206,13 @@ export default class NewClass extends cc.Component {
}
const canvas = cc.find("Canvas");
const bg = cc.find("bg/bg", this.node);
getSprNodeByUrl(bg_image_url, (sf)=>{
getSprNodeByUrl(bg_image_url, (sf) => {
const sx = canvas.width / sf.node.width;
const sy = canvas.height / sf.node.height;
bg.getComponent(cc.Sprite).spriteFrame = sf.spriteFrame;
bg.scale = Math.max(sx, sy);
cc.find("bg/bg_default", this.node).active = false;
cc.find("bg/bg", this.node).active = true;
})
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment