如何解决CCSprite颜色混合,类似于UIImage上的kCGBlendModeColor
|| 我试图在精灵图像上叠加颜色,并对如何将颜色与精灵混合有疑问。我使用以下updateImageTint
例程将颜色叠加在UIImage
上,并且输出是我想要的。图像保持白色,但是灰色阴影被指定的覆盖颜色饱和或烧毁。参数kCGBlendModeColor
似乎可以实现标准UIImage
色彩融合。
但是,我试图使用精灵来获得相同的效果,但是颜色看起来就像是在整个图像,白色区域以及所有区域之上的着色。我假设这是一个混合问题。是否可以传递给setBlendFunc以获取与以下“ 0”方法相匹配的输出的一组参数?
我已经尝试过...但是没有运气
[spritetoAdjust setBlendFunc: (ccBlendFunc) { GL_ONE,GL_ONE }];
[spritetoAdjust setColor:ccc3(red*255.0,green*255.0,blue*255.0)];
-(UIImage*) updateImageTint:(UIImage*) img toColor:(UIColor*) toColor
{
// begin a new image context,to draw our colored image onto
UIGraphicsBeginImageContext(img.size);
// get a reference to that context we created
CGContextRef context = UIGraphicsGetCurrentContext();
// set the fill color
UIColor *color = toColor;
[color setFill];
// translate/flip the graphics context (for transforming from CG* coords to UI* coords
CGContextTranslateCTM(context,img.size.height);
CGContextScaleCTM(context,1.0,-1.0);
// set the blend mode to color burn,and the original image
CGContextSetBlendMode(context,kCGBlendModeColor);
CGRect rect = CGRectMake(0,img.size.width,img.size.height);
CGContextDrawImage(context,rect,img.CGImage);
// set a mask that matches the shape of the image,then draw (color burn) a colored rectangle
CGContextClipToMask(context,img.CGImage);
CGContextAddRect(context,rect);
CGContextDrawPath(context,kCGPathFill);
// generate a new UIImage from the graphics context we drew onto
UIImage *coloredImg = UIGraphicsGetimageFromCurrentimageContext();
UIGraphicsEndImageContext();
//return the color-burned image
return coloredImg;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。