Colors CCSprite颜色混合类似于UIImage上的kCGBlendModeColor
我试图在雪碧图像上叠加颜色,并对如何将颜色与雪碧混合有疑问。我使用了下面的Colors CCSprite颜色混合类似于UIImage上的kCGBlendModeColor,colors,overlay,uicolor,ccsprite,blending,Colors,Overlay,Uicolor,Ccsprite,Blending,我试图在雪碧图像上叠加颜色,并对如何将颜色与雪碧混合有疑问。我使用了下面的updateImageTint例程在UIImage上叠加颜色,输出就是我所希望的。该图像保持白色,但灰色的阴影会被指定的覆盖颜色饱和或烧焦。paramkCGBlendModeColor似乎可以实现标准UIImage颜色混合 然而,我尝试使用精灵来获得相同的效果,但是颜色看起来就像是整个图像、白色区域和所有区域上的颜色。我想这是一个混合问题。是否有一组参数可以传递给setBlendFunc以获得与下面的updateImage
updateImageTint
例程在UIImage
上叠加颜色,输出就是我所希望的。该图像保持白色,但灰色的阴影会被指定的覆盖颜色饱和或烧焦。paramkCGBlendModeColor
似乎可以实现标准UIImage
颜色混合
然而,我尝试使用精灵来获得相同的效果,但是颜色看起来就像是整个图像、白色区域和所有区域上的颜色。我想这是一个混合问题。是否有一组参数可以传递给setBlendFunc以获得与下面的updateImageTint
方法匹配的输出
我试过了…但是运气不好
[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, 0, 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, 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, rect, 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;
}