Game Development Reference
In-Depth Information
float whiter = 0.6;
float c2alpha = 0.5;
float c3aplha = 0.3;
if (self.variant == VARIATION_RED){
color1 = [UIColor colorWithRed:1.0 green:whiter blue:whiter alpha:1.0];
color2 = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:c2alpha];
color3 = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:c3aplha];
} else if (self.variant == VARIATION_GREEN){
color1 = [UIColor colorWithRed:whiter green:1.0 blue:whiter alpha:1.0];
color2 = [UIColor colorWithRed:0.0 green:1.0 blue:0.0 alpha:c2alpha];
color3 = [UIColor colorWithRed:0.0 green:1.0 blue:0.0 alpha:c3aplha];
} else if (self.variant == VARIATION_BLUE){
color1 = [UIColor colorWithRed:whiter green:whiter blue:1.0 alpha:1.0];
color2 = [UIColor colorWithRed:0.0 green:0.0 blue:1.0 alpha:c2alpha];
color3 = [UIColor colorWithRed:0.0 green:0.0 blue:1.0 alpha:c3aplha];
} else if (self.variant == VARIATION_CYAN){
color1 = [UIColor colorWithRed:whiter green:1.0 blue:1.0 alpha:1.0];
color2 = [UIColor colorWithRed:0.0 green:1.0 blue:1.0 alpha:c2alpha];
color3 = [UIColor colorWithRed:0.0 green:1.0 blue:1.0 alpha:c3aplha];
} else if (self.variant == VARIATION_MAGENTA){
color1 = [UIColor colorWithRed:1.0 green:whiter blue:1.0 alpha:1.0];
color2 = [UIColor colorWithRed:1.0 green:0.0 blue:1.0 alpha:c2alpha];
color3 = [UIColor colorWithRed:1.0 green:0.0 blue:1.0 alpha:c3aplha];
} else if (self.variant == VARIATION_YELLOW){
color1 = [UIColor colorWithRed:1.0 green:1.0 blue:whiter alpha:1.0];
color2 = [UIColor colorWithRed:1.0 green:1.0 blue:0.0 alpha:c2alpha];
color3 = [UIColor colorWithRed:1.0 green:1.0 blue:0.0 alpha:c3aplha];
}
UIColor* color4 = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
CGColorRef clr[] = { [color1 CGColor], [color2 CGColor] , [color3 CGColor], [color4 CGColor]};
CFArrayRef colors = CFArrayCreate(NULL, (const void**)clr, sizeof(clr) / sizeof(CGColorRef),
&kCFTypeArrayCallBacks);
CGGradientRef grad = CGGradientCreateWithColors(space, colors, locations);
CGColorSpaceRelease(space);
CGContextDrawRadialGradient(context, grad, CGPointMake(self.radius, self.radius), 0,
CGPointMake(self.radius, self.radius), self.radius, 0);
CGGradientRelease(grad);
}
In Listing 7-25, we want to draw a simple radial gradient with the color appropriate to the variant at
the center and transparent at the edge. We have to create a four-color gradient to achieve a nice-
looking Comet. The first color is mostly white and fully opaque, the next two colors are the color of
the variant with two different alpha values. The last color will be completely transparent. The function
CGContextDrawRadialGradient draws the radial gradient at the center of the actor with the first color
and creates a smooth transition to the transparent edge of the actor.
Search WWH ::




Custom Search