标签 creator 下的文章

动态修改场景的canvas属性设置,需要两套布局节点坐标信息

    start() {
        this.updateCanvasSize();
        cc.view.setResizeCallback(() => {
            this.updateCanvasSize();
        })
    },

    // 自由切换横竖屏,动态设置设计分辨率和适配模式。
    updateCanvasSize() {
        let size = cc.view.getFrameSize();
        if (size.width > size.height) {
            this.canvas.fitWidth = false;
            this.canvas.fitHeight = true;
            this.canvas.designResolution = cc.size(1920, 1080);
            this.showLandscape();
        } else {
            this.canvas.fitWidth = true;
            this.canvas.fitHeight = false;
            this.canvas.designResolution = cc.size(1080, 1920);
            this.showPortait();
        }
    },

注意微信上必须是bin后缀的,才能以二进制模式读取文件。

微信返回的是 ArrayBuffer, chrome返回的是Uint8Array。

var url = cc.url.raw("resources/bin/data.bin");
cc.loader.load({ url: url, type: "binary", }, function (err, data) {
    if (data instanceof ArrayBuffer){
        data = new Uint8Array(data);
    }
    console.log("err ===", err);
    console.log("data ===", data.length);
});