有没有我不是信口开河,如果你找到了记得分享一下,我目前没找到哦~
有的话你就贴地址上来,大家也能心服口服
对了,问下,假如挨的很近的2张不规则的按钮图片所有的像素都完全相同(比如都是全黑或者全白),那么是否可以检测到点击的是不同的图片按钮呢?
可以的,判断的是alpha.
1赞
很强,希望对接下3.8.1,感激不尽
static readPixels(node: Node, flipY = true): Uint8Array {
const texture = node.getComponent(Sprite)!.spriteFrame!.texture;
const { width, height } = texture;
const gfxTexture = texture.getGFXTexture();
const gfxDevice = texture['_getGFXDevice']();
const bufferViews = [];
const region = new gfx.BufferTextureCopy;
const buffer = new Uint8Array(width * height * 4);
region.texExtent.width = width;
region.texExtent.height = height;
bufferViews.push(buffer);
gfxDevice?.copyTextureToBuffers(gfxTexture, bufferViews, [region]);
if (flipY) {
let i = 0, len1 = height / 2, len2 = width * 4, j: number, idx0: number, idx1: number;
while (i < len1) {
j = 0;
while (j < len2) {
idx0 = i * len2 + j;
idx1 = (height - i - 1) * len2 + j++;
[buffer[idx0], buffer[idx1]] = [buffer[idx1], buffer[idx0]];
}
i++;
}
}
return buffer;
}
不用客气,我也是用的别人的
另外,gfx容易忘记从cc导入,需要额外注意下
7赞
大佬,太牛了,这两天我用你那个挖空shader,升级了个3.x的挖多孔的,现在在里面加功能,嗷嗷好用
取色这个功能用snipaste这个软件,免费的好像是,美术同学也用这个
还是定价问题引发的哈哈哈。
- 重载hittest的接口。
- 获取纹理信息spriteFrame.getTexture,采用gl.framebufferTexture2D。
- 将触摸的点转到纹理上对应的点。
- 然后通过 gl.readPixels拿到对应点的像素。
- 按照rgba判断就好了。
刚到家准备做,一看你连答案都发出来了
上班摸鱼警告 
还有这位大佬的,论坛里面有很多有用的代码,可惜没人关注
有个 问题 获取纹理信息spriteFrame.getTexture,采用gl.framebufferTexture2D。是获取的渲染前 还是渲染后的 纹理。
渲染前的,原始纹理。
我不是要获取像素的功能,我说的是2个挨的很近的按钮,类似人家那样,不要误会,读取像素我也行
什么顶级理解。。。。不回复了。
如果真的行的话,也不至于这几百行代码都不写,说话大家都会,dont say any shit,show your absolute code
你看马赛克才有资格说这话
