这个就是要确定你要填的是那个区域是难点,解决了剩下就是涂色而已,你可以对像素级操作,采用图遍历,遇到不是白色不继续走,这样就可以遍历出点击像素所在白色区域所有白色,填色就好,也就是上面说的Flood Fill算法,推荐这个图搞透明底白色线比较好,可以方便换线颜色也可以方便判断填涂区域,背景可以任意换背景图
const {ccclass, property} = cc._decorator;
@ccclass
export default class NewClass extends cc.Component {
@property({type: cc.Texture2D})
texture: cc.Texture2D = null;
start () {
let rt = new cc.RenderTexture();
rt.initWithSize(this.texture.width, this.texture.height);
rt.drawTextureAt(this.texture, 0, 0);
// data就是这个texture的rgba值数组
let data = rt.readPixels();
console.log(data);
}
}