分类 Creator 下的文章

// uuid 解码参数
const separator = '@';
const HexChars = '0123456789abcdef'.split('');
const _t = ['', '', '', ''];
const UuidTemplate = _t.concat(_t, '-', _t, '-', _t, '-', _t, '-', _t, _t, _t);
const Indices = UuidTemplate.map((x, i) => (x === '-' ? NaN : i)).filter(Number.isFinite);
const BASE64_KEYS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
const values = new Array(123); // max char code in base64Keys
for (let i = 0; i < 123; ++i) { values[i] = 64; } // fill with placeholder('=') index
for (let i = 0; i < 64; ++i) { values[BASE64_KEYS.charCodeAt(i)] = i; }
const BASE64_VALUES = values;

// 将3.8的uuid解码
function decodeUuid (base64) {
    const strs = base64.split(separator);
    const uuid = strs[0];
    if (uuid.length !== 22) {
        return base64;
    }
    UuidTemplate[0] = base64[0];
    UuidTemplate[1] = base64[1];
    for (let i = 2, j = 2; i < 22; i += 2) {
        const lhs = BASE64_VALUES[base64.charCodeAt(i)];
        const rhs = BASE64_VALUES[base64.charCodeAt(i + 1)];
        UuidTemplate[Indices[j++]] = HexChars[lhs >> 2];
        UuidTemplate[Indices[j++]] = HexChars[((lhs & 3) << 2) | rhs >> 4];
        UuidTemplate[Indices[j++]] = HexChars[rhs & 0xF];
    }
    return base64.replace(uuid, UuidTemplate.join(''));
}

太久没装CocosCreator环境,重新装了一下。VS需要补充下面这个:

https://docs.cocos.com/creator/manual/zh/getting-started/coding-setup.html

{
    "search.exclude": {
        "**/node_modules": true,
        "**/bower_components": true,
        "build/": true,
        "temp/": true,
        "library/": true,
        "**/*.anim": true
    },
    "files.exclude": {
        "**/.git": true,
        "**/.DS_Store": true,
        "**/*.meta": true,
        "library/": true,
        "local/": true,
        "temp/": true
    }
}

做游戏通常有时会通过屏蔽屏幕其它按扭,最简单方法就是显示一个空NODE设置大小。挡住事件,然后点击有效区时。才把事件穿透下去。

this.node._touchListener.setSwallowTouches(false)

在我们做游戏的时候经常会有新手引导,让用户点某个区域,又或者说我们需要做个刮刮乐游戏。那就需要动态画图或将图中间扣空。

所以,我们现在通过Mask来实现:
Mask设置:
202008201215.jpg

具体代码如下:

let mask:cc.Mask = this.node.getChildByName("mask").getComponent(cc.Mask);
var stencil = mask._clippingStencil;
var color = cc.color(255, 255, 255, 0);
stencil.drawPoly(mask._calculateCircle(cc.p(0,0),cc.p(50,50), 64), color, 0, color);
stencil.drawPoly(mask._calculateCircle(cc.p(50,0),cc.p(50,50), 64), color, 0, color);
stencil.drawPoly(mask._calculateCircle(cc.p(-50,0),cc.p(50,50), 64), color, 0, color);

最终效果图:
202008201216.jpg

PS:鼠标移动代码这里就不演示,自行监听touchBegin,touchMoved等事件处理就行。
Creator 版本: 1.10.3