不规则图片按钮,如何判断点击事件

GIF

这个是怎么实现的

你这是正方行,12 的间隔线正好就是 12 的中垂线,你能用菱形来试一试吗,想象一下,把正方行压扁,间隔线就会和中垂线发生偏离,偏离的多了再点中垂线旁边就会误判

:smile:特殊情况特殊处理 我只是觉得他的截图让我觉得他的需求可以实现


assets.zip (4.2 KB)

1赞

牛哇牛哇 :grin:

因为块形状很简单。所以可以算出每个块的边界点。
然后通过potinInPolygon去判断。这个是2.4.6的代码

        const _landArray = this.node.getChildByName('landArray').children;
        _landArray.forEach(land => {
            let { width, height, x, y } = land;
            width /= 2;
            height /= 2;
            land.__rect = [
                cc.v2(x, y + height),
                cc.v2(x + width, y),
                cc.v2(x, y - height),
                cc.v2(x - width, y)
            ];
        })
        this.node.on('touchstart', e => {
            const _pos = e.getLocation().sub(cc.v2(this.node.width / 2, this.node.height / 2));
            const _land = _landArray.find(land => cc.Intersection.pointInPolygon(_pos, land.__rect));
            _landArray.forEach(land => console.log(land.__rect.map(v => v.x + ',' + v.y)));
            if (_land instanceof cc.Node) cc.tween(_land).to(0.2, { color: cc.Color.RED }).to(0.2, { color: cc.Color.WHITE }).start();
        })
4赞

去除之后,图片还是矩形啊,还是会有透明区域滴 :rofl:

老哥你这个原生端可以吗?

mark一个

mark 一个

好用123456