cocos2dx 屏幕自适应

本文探讨了针对不同设备分辨率的设计方法,特别是采用16:9作为基准设计分辨率,并介绍了如何通过调整后备缓冲区大小等参数实现跨平台适配。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

iphone4 / 4s        960*640            3:2

iphone5              1136*640          16:9

ipad 2 / mini        1024*768          4:3

newpad               2048*1536        4:3

三星Note2           1280*720         16:9

小米2                  1280*720         16:9

三星s4                1920*1080       16:9

HTC One            1920*1080       16:9

sony L35h          1920*1080       16:9

 

cocos2dx 屏幕自适应 - long_wtf - Jeanny

 

由此可见,铺天盖地16:9 。就用16:9来设计,其他分辨率来适配。取1280*720为开发分辨率。

以下是涉及的函数。

    /**
     * Set the design resolution size.
     * @param width Design resolution width.
     * @param height Design resolution height.
     * @param resolutionPolicy The resolution policy desired, you may choose:
     *                         [1] kResolutionExactFit Fill screen by stretch-to-fit: if the design resolution ratio of width to height is different from the screen resolution ratio, your game view will be stretched.
     *                         [2] kResolutionNoBorder Full screen without black border: if the design resolution ratio of width to height is different from the screen resolution ratio, two areas of your game view will be cut.
     *                         [3] kResolutionShowAll  Full screen with black border: if the design resolution ratio of width to height is different from the screen resolution ratio, two black borders will be shown.
     */
    virtual void setDesignResolutionSize(float width, float height, ResolutionPolicy resolutionPolicy);

  

    /** returns visible size of the OpenGL view in points.
     *  the value is equal to getWinSize if don't invoke
     *  CCEGLView::setDesignResolutionSize()
     */
    CCSize getVisibleSize();
   


    /** returns visible origin of the OpenGL view in points.
     */
    CCPoint getVisibleOrigin();

    /**
     * Get the frame size of EGL view.
     * In general, it returns the screen size since the EGL view is a fullscreen view.
     */
    virtual const CCSize& getFrameSize() const;

 

一共四个函数,其实包含了4种数据。大小的单位均为像素。

design resolution size:后备缓冲区大小。

//////// Scale actor:纹理缩放系数,将图片放大的倍数。  2.1.4不要改变此值。系统会自动缩放。

visible size :如果后备缓冲区在屏幕上时间显示的大小。

visible origin :后备缓冲区与屏幕左下角 0,0 点重合的坐标。

 frame size :实际屏幕的大小。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值