l

成都手游码农一枚
随笔 - 32, 文章 - 0, 评论 - 117, 引用 - 0
数据加载中……

[cocos2d-x] iphone5 填充黑边适配方案。

看不惯黑边又不想拉伸的解决方案,很多游戏也这么处理,直接用边框填充黑边。


    // Set RootViewController to window
    if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
    {
        EAGLView *__glView = [EAGLView viewWithFrame: [window bounds]
                                         pixelFormat: kEAGLColorFormatRGBA8
                                         depthFormat: GL_DEPTH_COMPONENT16
                                  preserveBackbuffer: NO
                                          sharegroup:nil
                                       multiSampling:NO
                                     numberOfSamples:0];
        
        UIView* view = [[UIView alloc] initWithFrame:[window bounds]];
        [view setBackgroundColor:[UIColor blueColor]];
        
        // Use RootViewController manage EAGLView
        viewController = [[[RootViewController alloc] initWithNibName:nil bundle:nil] autorelease];
        viewController.wantsFullScreenLayout = YES;
        viewController.view = __glView;
        
        // warning: addSubView doesn't work on iOS6
        [window addSubview: viewController.view];
        
        s_rootView = __glView;
        s_rootViewController = viewController;
        
        // Set RootViewController to window
        [window makeKeyAndVisible];
        [[UIApplication sharedApplication] setStatusBarHidden: YES];
        
        [window setRootViewController:viewController];
    }
    else
    {
        bool i5 = false;
        
        CGRect r = [window bounds];
        float f = 1.0f * r.size.height / r.size.width - 960.0f / 640;
        //printf("---- %f,%f,%f", r.size.height, r.size.width, f);
        if (!(f < 0.001 && f > -0.001))
        {
            i5 = true;
        }
        
        EAGLView *__glView = [EAGLView viewWithFrame: CGRectMake(0, i5 ? 44 : 0, 320, 480)//[window bounds]
                                         pixelFormat: kEAGLColorFormatRGBA8
                                         depthFormat: GL_DEPTH_COMPONENT16
                                  preserveBackbuffer: NO
                                          sharegroup:nil
                                       multiSampling:NO
                                     numberOfSamples:0];
        
        UIView* rootView = [[[UIView alloc] initWithFrame:[window bounds]] autorelease];
        [rootView addSubview:__glView];
        
        if (i5)
        {
            // top
            UIImageView* topView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"top.png"]] autorelease];
            [rootView addSubview:topView];
            [topView setFrame:CGRectMake(0, 0, 320, 44)];
        
            // bottom
            UIImageView* bottomView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bottom.png"]] autorelease];
            [rootView addSubview:bottomView];
            [bottomView setFrame:CGRectMake(0, 524, 320, 44)];
        
            s_sharedApplication.setKeyboardOffsetY(44 * 2);
        }
        
        // Use RootViewController manage EAGLView
        viewController = [[[RootViewController alloc] initWithNibName:nil bundle:nil] autorelease];
        viewController.wantsFullScreenLayout = YES;
        viewController.view = rootView;

        // use this method on ios6
        [window setRootViewController:viewController];
        
        s_rootView = rootView;
        s_rootViewController = viewController;
        
        // Set RootViewController to window
        [window makeKeyAndVisible];
        [[UIApplication sharedApplication] setStatusBarHidden: YES];
    }

posted on 2013-07-02 10:56 l1989 阅读(2012) 评论(0)  编辑 收藏 引用 所属分类: 游戏


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理