Я пытаюсь наложить цвет на изображение спрайта и у меня есть вопросы о том, как смешать цвет со спрайтом.Я использовал следующую подпрограмму updateImageTint
для наложения цвета на UIImage
, и результат - это то, на что я надеюсь.Изображение сохраняет белый цвет, но оттенки серого насыщаются или сжигаются с указанным наложенным цветом.Параметр kCGBlendModeColor
, кажется, подходит для стандартного 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;
}