Commit 1720e51d authored by 范雪寒's avatar 范雪寒

feat: storyBox 适配

parent da5c2128
......@@ -618,28 +618,67 @@ cc.Class({
this.hideWaitingLetters();
callback && callback();
if (this.bundleType == 'StoryBox') {
canvas.getComponent(cc.Widget).updateAlignment();
middleLayer.getComponent(cc.Widget).updateAlignment();
const frameSize = cc.view.getFrameSize();
console.log(`Canvas.size = ${canvas.width}, ${canvas.height}`);
console.log(`frameSize.size = ${frameSize.width}, ${frameSize.height}`);
console.log(`middleLayer.size = ${middleLayer.width}, ${middleLayer.height}`);
const scale = (middleLayer.width / frameSize.width);
console.log('scale = ' + scale);
const middleLayerWidget = middleLayer.getComponent(cc.Widget);
middleLayerWidget.isAlignHorizontalCenter = true; // Boolean 是否水平方向对齐中点,开启此选项会将水平方向其他对齐选项取消。
middleLayerWidget.isAlignVerticalCenter = true; // Boolean 是否垂直方向对齐中点,开启此项会将垂直方向其他对齐选项取消。
// middleLayer.removeComponent(cc.Widget);
middleLayer.width = frameSize.width * scale;
middleLayer.height = frameSize.height * scale;
this.node.removeComponent(cc.Widget);
this.updateScale();
}
});
});
});
},
updateScale() {
console.log("updateScale");
const canvas = cc.find("Canvas");
const canvasComponent = canvas.getComponent(cc.Canvas);
const canvasSize = cc.view.getCanvasSize();
const designSize = cc.view.getDesignResolutionSize();
if (canvasComponent.fitHeight && canvasComponent.fitWidth) {
console.log("fit both");
const scale = Math.max(
designSize.width / canvasSize.width,
designSize.height / canvasSize.height
);
const scaleHeight = this.node.height / canvasSize.height;
this.node.width = canvasSize.width * scaleHeight;
this.node.scale = scale / scaleHeight;
const pos = this.node.parent.convertToNodeSpaceAR(
canvas.convertToWorldSpaceAR(cc.v2(0, 0))
);
this.node.setPosition(pos);
return;
}
if (canvasComponent.fitHeight && !canvasComponent.fitWidth) {
console.log("fit height");
const scale = designSize.height / canvasSize.height;
const scaleHeight = this.node.height / canvasSize.height;
this.node.width = canvasSize.width * scaleHeight;
this.node.scale = scale / scaleHeight;
this.node.x = (this.node.width * this.node.scale) / 2;
this.node.y = (this.node.height * this.node.scale) / 2;
return;
}
if (!canvasComponent.fitHeight && canvasComponent.fitWidth) {
console.log("fit width");
const scale = designSize.width / canvasSize.width;
const scaleWidth = this.node.width / canvasSize.width;
this.node.height = canvasSize.height * scaleWidth;
this.node.scale = scale / scaleWidth;
this.node.x = (this.node.width * this.node.scale) / 2;
this.node.y = (this.node.height * this.node.scale) / 2;
return;
}
},
loadBundleByConf(conf, callback) {
if (cc.sys.isNative && cc.sys.os == cc.sys.OS_IOS) {
this.loadBundle(conf.ios, callback);
......
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