I have a Quartz 2D game which draws directly onto a context. For this reason I am having to adapt the code so that it scales if appropriate for a Retina display. I am doing this using the following code:
- (CGFloat) displayScale
{
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
return [[UIScreen mainScreen]scale];
}
else
{
return 1.0;
}
}
What I am now struggling with is how to manipulate my Quartz context in my -drawRect:
method to mulitply by the returned scale
value. Can anyone help me with this code ?
You don't need to change anything in your Quartz code to account for the Retina display. If the correct contentScaleFactor
is set on your UIView or CALayer using code like the following:
if ([view respondsToSelector:@selector(setContentScaleFactor:)])
{
view.contentScaleFactor = [[UIScreen mainScreen] scale];
}
the 2-D drawing you do within -drawRect:
or -drawInContext:
will be automatically rendered sharply for the Retina display. Remember that the coordinates you specify for the Quartz drawing will be in points, not pixels. With a scale factor of 2.0 for a Retina display, 1 point = 2 pixels.
See the "Updating Your Custom Drawing Code" section in the iOS Application Programming Guide for more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With