Life,Cocos Creator
Cocos Creator

cocos creator 获取spine的boundingBox附件信息

let attachment = this.goblin.getAttachment('head-bb', "head")
let slot = this.goblin.findSlot("head-bb")
let arr = {}
let data = attachment.computeWorldVertices(slot, 0, attachment.worldVerticesLength, arr, 0, 2)
cc.log(arr)

cocos creator wap模式下横竖屏动态适应

动态修改场景的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();
        }
    },

cocos creator 加载二进制

注意微信上必须是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);
});