两分钟让你明白cocos2dx的屏幕适配策略
闲来无事,整理了一下cocos2dx的屏幕适配策略,本文适用于想快速理解cocos2dx适配的开发者。 我们先假设:以854 * 480 的屏幕为标准进行开发,当然,这也就是cocos2dx所说的 设计分辨率 (Design Resolution)。 先介绍几个cocos2dx的常用函数: CCEGLView :: sh
闲来无事,整理了一下cocos2dx的屏幕适配策略,本文适用于想快速理解cocos2dx适配的开发者。
我们先假设:以854 * 480 的屏幕为标准进行开发,当然,这也就是cocos2dx所说的设计分辨率(Design Resolution)。
先介绍几个cocos2dx的常用函数:
CCEGLView::sharedOpenGLView()->setDesignResolutionSize()//设计分辨率大小(即开发时为基准的屏幕分辨率)
CCEGLView::sharedOpenGLView()->setFrameSize() //设置win32模拟器的分辨率
CCEGLView::sharedOpenGLView()->getFrameSize() //屏幕分辨率,实际的硬件参数
一、准备图片资源
准备一张854 * 480 的图片,这里我用红色线对图片的四个边描了一下边,以保证图片不能完全显示时,方便我们看出来。
二、直接使用三种适配策略
//kResolutionExactFit x,y都拉伸,使铺满屏幕
//kResolutionNoBorder 一个方向铺满屏幕,另外一个方向超出屏幕
//kResolutionShowAll 854 * 480 的设计区域全部可见,但是可能留有黑边(如在960 * 640的屏幕上)
以上三种原理这里不再赘述,详细可参考这里:http://www.ityran.com/archives/4809
既然我们是以854 * 480 为基准来开发游戏,那么我们这里将设计分辨率设置为854 * 480 。
[cpp] view plaincopyprint?
- pEGLView->setDesignResolutionSize(854 ,480 ,kResolutionNoBorder);
三、看效果
下面,我们设置win32模拟器的分辨率为960*640,来看一下三种适配策略的效果。
kResolutionExactFit效果:
[cpp] view plaincopyprint?
- pEGLView->setDesignResolutionSize(854 ,480 ,kResolutionExactFit);
这里可以看出,由于适配策略拉伸,x,y方向都填满了,同时也没有超出屏幕的情况,但是和下面两张图片比较,图片变形了。
kResolutionNoBorder效果:
[cpp] view plaincopyprint?
- pEGLView->setDesignResolutionSize(854 ,480 ,kResolutionNoBorder);
这里也可看出,左右的红色描边都不见了,由于屏幕比例和设计比例不一致,该适配策略能够铺满屏幕,但是原图超出了屏幕。
kResolutionShowAll效果:
[cpp] view plaincopyprint?
- pEGLView->setDesignResolutionSize(854 ,480 ,kResolutionShowAll);
这里,该策略使设计分辨率的所有内容均可见,但是由于实际屏幕比例和设计分辨率的比例不一致,会出现黑边的情况。
四、对资源分辨率的解释
对于一个游戏,多套图片资源,涉及到在不同屏幕分辨率情况下就需要使用不同的图片资源了,直接点说,大屏幕用大图,小屏幕用小图。
同时,由于图片资源宽高比和设计分辨率的宽高比可能不一致,也需要按照某个比例对图片资源进行缩放。
详情见:http://www.ityran.com/archives/4809
以上是个人对cocos2dx分辨率适配进行了一些简单的介绍,适合大家快速理解整套适配策略,更加详细的原理可参考文章给出的链接。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What many users are most concerned about is whether the miniLED screen will hurt the eyes. In fact, although the brightness of this screen can reach extremely high, it will not hurt the eyes and can still be used normally. Does the miniled screen hurt your eyes? Answer: It does not hurt your eyes. Although the brightness of the miniLED screen will be higher, it will not continue to maintain this brightness during daily use. It will only be displayed when the brightness needs to be increased, so it will not always maintain high brightness and hurt the eyes. This peak brightness is also for better Good presentation and expression. MiniLED screen introduction 1. MiniLED backlight display technology uses backlight, so the biggest difference from LCD is the backlight layer 2. Compared with LCD screen, the performance of miniLED will be higher.

When many friends are using their mobile phones, they suddenly find that the operation interface of the mobile phone has turned into "black and white" color. They don't know what causes it or how to solve it. This article uses Android mobile phones as an example to teach you how to make it work. The color of the mobile phone's operating interface returns to normal. 1. Set up the interface of the mobile phone and find the "gear-shaped" icon in the operation interface. As shown below: Click this icon to enter the phone’s settings interface. 2. Options The operating interface of the mobile phone has changed to black and white, which is related to the "Display" setting of the mobile phone. After entering the settings interface of the mobile phone, find the "Display and Theme" option in the drop-down menu, as shown below: Then click "Display and Theme" option to enter the details page. 3. After changing the screen color and entering the "Display and Theme" option, find the "

Screenshot feature not working on your iPhone? Taking a screenshot is very easy as you just need to hold down the Volume Up button and the Power button at the same time to grab your phone screen. However, there are other ways to capture frames on the device. Fix 1 – Using Assistive Touch Take a screenshot using the Assistive Touch feature. Step 1 – Go to your phone settings. Step 2 – Next, tap to open Accessibility settings. Step 3 – Open Touch settings. Step 4 – Next, open the Assistive Touch settings. Step 5 – Turn on Assistive Touch on your phone. Step 6 – Open “Customize Top Menu” to access it. Step 7 – Now you just need to link any of these functions to your screen capture. So click on the first

Many friends find that when adjusting the resolution of the computer, the screen resolution is increased and the screen is black. What should I do? In fact, the screen resolution of our computer can also be adjusted freely. If we cannot adjust it, then either the graphics card is faulty. If there is a problem, or we have not set up the computer properly, today the editor has brought a solution to the black screen when the computer screen resolution is increased. Let’s take a look at the details. Solution to black screen when the screen resolution is increased 1. Turn on the computer and press the F8 key to enter "Advanced Mode". 2. Select "Safe Mode" and press Enter to confirm. 3. After entering, right-click on a blank space on the desktop, select screen resolution, select a resolution suitable for the screen, and click OK after the settings are completed. Resolution related issues>>>Screen

I believe many friends have encountered the problem that their mobile phones suddenly prompt: Do not cover the top of the screen. So why does the mobile phone suddenly appear like this? Let’s take a look together below. In fact, when this happens, something is blocking the distance sensor of the phone, so this prompt is received on the screen of the phone. So why did I suddenly receive such a prompt? In fact, it may be that you have accidentally turned on the [anti-accidental touch mode] on your phone, so this problem occurs. So how do we close it? In fact, the method is very simple. Let’s take a look at it together. Method 1: Directly follow the on-screen prompts to close using the shortcut key combination. Method 2: If the above method does not work, you can also open the phone’s [Settings]

Although it will be a long time before the release of the iPhone 16 series, there have been constant revelations about the appearance and configuration. According to Korean media SisaJournal, Apple plans to introduce new ultra-narrow bezel technology in the upcoming iPhone 16 series of mobile phones. The technology involves rolling internal copper wires into a more compact structure to reduce the bezel width of the phone's bottom display, allowing for a larger display. This innovative move aims to enhance the user experience, allowing users to enjoy a wider field of view and a more immersive entertainment experience. Apple has always been committed to continuously improving its product design and technology to bring more advanced functions and performance to users. The launch of the iPhone 16 series of mobile phones will further consolidate Apple’s leadership in smart phones. According to @SnapaDigital, Apple’s new

Deleted something important from your home screen and trying to get it back? You can put app icons back on the screen in a variety of ways. We have discussed all the methods you can follow and put the app icon back on the home screen. How to Undo Remove from Home Screen in iPhone As we mentioned before, there are several ways to restore this change on iPhone. Method 1 – Replace App Icon in App Library You can place an app icon on your home screen directly from the App Library. Step 1 – Swipe sideways to find all apps in the app library. Step 2 – Find the app icon you deleted earlier. Step 3 – Simply drag the app icon from the main library to the correct location on the home screen. This is the application diagram

According to news on July 23, blogger Digital Chat Station broke the news that the battery capacity of Xiaomi 15 Pro has been increased to 6000mAh and supports 90W wired flash charging. This will be the Pro model with the largest battery in Xiaomi’s digital series. Digital Chat Station previously revealed that the battery of Xiaomi 15Pro has ultra-high energy density and the silicon content is much higher than that of competing products. After silicon-based batteries are tested on a large scale in 2023, second-generation silicon anode batteries have been identified as the future development direction of the industry. This year will usher in the peak of direct competition. 1. The theoretical gram capacity of silicon can reach 4200mAh/g, which is more than 10 times the gram capacity of graphite (the theoretical gram capacity of graphite is 372mAh/g). For the negative electrode, the capacity when the lithium ion insertion amount reaches the maximum is the theoretical gram capacity, which means that under the same weight
