Question

So I worked on an iPhone game several years ago that uses CGPointMake calls hundreds of times for some OpenGL stuff. That was back when 480 was the only size for landscape phones, but now I'd like to support the 568 point size display. The problem is things aren't centered now and theres this big empty black vertical bar on the right side of the screen

I was wondering what the best way to fill the screen again would be without rewriting these hundreds of CGPoint calls. I was thinking if I could overload CGPointMake somehow to offset each one by (44,0) it would help to center things. Or maybe there's a way with OpenGL to shift everything in one direction? I'm not overly familiar with OpenGL so I'm not sure where the best place to start would be - any help is greatly appreciated!

Was it helpful?

Solution

Overloading CGPointMake sounds like too much magic to me. Are all these occurences really just centering the point? In that case you could write the screen-agnostic version:

// Or something similar given your UI orientation and transformations
CGPointMake(CGRectGetMidY([[UIScreen mainScreen] bounds]), someY);

And since that’s quite a mouthful, you could introduce a macro or a function:

CGPoint CGPointMakeHorizontalCenter(CGFloat y) { … }

Then bite the bullet, write a nice regular expression and replace all centering CGPointMake references with calls to this CGPointMakeHorizontalCenter.

(This all assumes you just need to center things better. In reality, maybe you also have to change some assets to better fill the screen? I think you could just stretch your whole older rendering code to fill the screen, but that would look ugly.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top