IT Technology

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)

std::map 注意事项

std::map 不能直接访问下标,否则size会自动变大。这坑和js如出一辙。
查询需用find,删除需用erase

    auto it = _tilesAniData.find(z);
    if (it != _tilesAniData.end()) { // remove old data
        delete it->second;
        _tilesAniData.erase(z);
    }

遍历

    for(auto it = _tilesAniData.begin(); it != _tilesAniData.end(); ++it) {
        delete it->second;
    }

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();
        }
    },

iOS 12国行的特供联网提示框不弹出

非常蛋痛,必须请求带域名的http才能触发,直接ip地址不一定触发。

需要无脑请求一次带域名的网络。

local request = network.createHTTPRequest(function(event)
end, "http://cocos2d-lua.org", "GET")
request:start()

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);
});