开发者

Center a MacGLView in a Window

开发者 https://www.devze.com 2023-03-15 20:06 出处:网络
I have an cocos2D app that runs in 4/3 ratio and I want to enter fullscreen mode resizing the view to maintain the aspect ratio without showing black bars at screen sides. So, when the app enters full

I have an cocos2D app that runs in 4/3 ratio and I want to enter fullscreen mode resizing the view to maintain the aspect ratio without showing black bars at screen sides. So, when the app enters fullscreen, I do this:

NSRect aFrame=[[NSScreen mainScreen] frame];
[glView_ setFrameSize:NSMakeSize(aFrame.size.width,aFrame.size.height*1.2)];

This way I got fullscreen wide but (as I wanted) the ratio is untouched. My problem now is that the glview is not centered on screen. It extends from left bottom point so I got my game unevenly clipped (all clipping is done at top). I've trying to use [glview setFrameOrigin] and similar to select t开发者_C百科he visible portion of the view without success.

I just want to displace my view a certain number of pixels down so it shows the center area of whole view. Is it possible?.

Thanks in advice.


You are changing the dimensions of glView_, but not its origin.

NSRect aFrame=[[NSScreen mainScreen] frame];

CGFloat x = 0.0f;
CGFloat y = aFrame.size.height;
CGFloat width = aFrame.size.width;
CGFloat height = aFrame.size.height * 1.2f;

glView_.frame = NSRectFromCGRect((CGRectMake(x, y/2 - height / 2, width, height));
0

精彩评论

暂无评论...
验证码 换一张
取 消