Commit ec014a3d authored by 李维's avatar 李维

修改背景图的适配

以左上角为基准,高度铺满屏幕,横向保持相同比例
parent 5af51b9d
...@@ -14,10 +14,15 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -14,10 +14,15 @@ export default class SceneComponent extends MyCocosSceneComponent {
this._imageResList.push({ url: page.startBg }); this._imageResList.push({ url: page.startBg });
}); });
const bgNode = cc.find('Canvas/bg'); const bgNode = cc.find('Canvas/bg/startBg');
bgNode.color = cc.color(255, 255, 255); bgNode.color = cc.color(255, 255, 255);
const startBg = this.data.pageArr[this.currentPageIdx].startBg; const startBg = this.data.pageArr[this.currentPageIdx].startBg;
this.setNodeSpirteFrameByUrl(startBg, bgNode, resolve); this.setNodeSpirteFrameByUrl(startBg, bgNode, (frame)=>{
bgNode.x = bgNode.parent.width / -2;
bgNode.y = bgNode.parent.height / 2;
bgNode.scale = bgNode.parent.height / frame.height;
});
}) })
} }
...@@ -294,10 +299,14 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -294,10 +299,14 @@ export default class SceneComponent extends MyCocosSceneComponent {
book_right.active = true; book_right.active = true;
} }
const bgNode = cc.find('Canvas/bg'); const bgNode = cc.find('Canvas/bg/startBg');
bgNode.color = cc.color(255, 255, 255); bgNode.color = cc.color(255, 255, 255);
const startBg = this.data.pageArr[this.currentPageIdx].startBg; const startBg = this.data.pageArr[this.currentPageIdx].startBg;
this.setNodeSpirteFrameByUrl(startBg, bgNode); this.setNodeSpirteFrameByUrl(startBg, bgNode, (frame)=>{
bgNode.x = bgNode.parent.width / -2;
bgNode.y = bgNode.parent.height / 2;
bgNode.scale = bgNode.parent.height / frame.height;
});
} }
showTips(tips) { showTips(tips) {
...@@ -332,7 +341,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -332,7 +341,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
setNodeSpirteFrameByUrl(url: string, node: cc.Node, callBack = null) { setNodeSpirteFrameByUrl(url: string, node: cc.Node, callBack = null) {
cc.assetManager.loadRemote(url, (err, tex) => { cc.assetManager.loadRemote(url, (err, tex) => {
node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(tex); node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(tex);
callBack && callBack(); callBack && callBack(tex);
}); });
} }
} }
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