const pos_v2 = 世界坐标;
const color_as = camera_rt.targetTexture!.readPixels(pos_v2.x, pos_v2.y, 1, 1)!;
// 获得颜色
cc.color(color_as[0], color_as[1], color_as[2], color_as[3]);
使用实例
const camera_rt = this.nodes.cameraRT.getComponent(cc.CameraComponent)!;
camera_rt.targetTexture!.resize(cc.view.getDesignResolutionSize().width, cc.view.getDesignResolutionSize().height);
this.node.on(
cc.Node.EventType.TOUCH_MOVE,
(event: cc.EventTouch) => {
const pos_v2 = event.getUILocation();
const color_as = camera_rt.targetTexture!.readPixels(pos_v2.x, pos_v2.y, 1, 1)!;
this.nodes.color.sprite.color = cc.color(color_as[0], color_as[1], color_as[2], color_as[3]);
},
this
);