landscape or portrait

我们的程序是风景模式还是肖像模式?使用cocos2d-x在Win32平台做开发时,如何进行设置?在继续下面的教程之前,有必要弄清楚这些问题。

什么是风景模式?什么是肖像模式?

根据我的理解:宽度大于高度有着更宽阔的视野,适合欣赏风景;高度大于宽度能给站立的人物一个特写,适合画肖像。

在cocos2d-x代码中,对设备方向有这样的定义:

 1 /** @typedef ccDeviceOrientation
2 Possible device orientations
3 */
4 typedef enum {
5 /// Device oriented vertically, home button on the bottom
6 kCCDeviceOrientationPortrait = 0, // UIDeviceOrientationPortrait,
7 /// Device oriented vertically, home button on the top
8 kCCDeviceOrientationPortraitUpsideDown = 1, // UIDeviceOrientationPortraitUpsideDown,
9 /// Device oriented horizontally, home button on the right
10 kCCDeviceOrientationLandscapeLeft = 2, // UIDeviceOrientationLandscapeLeft,
11 /// Device oriented horizontally, home button on the left
12 kCCDeviceOrientationLandscapeRight = 3, // UIDeviceOrientationLandscapeRight,
13
14 // Backward compatibility stuff
15 CCDeviceOrientationPortrait = kCCDeviceOrientationPortrait,
16 CCDeviceOrientationPortraitUpsideDown = kCCDeviceOrientationPortraitUpsideDown,
17 CCDeviceOrientationLandscapeLeft = kCCDeviceOrientationLandscapeLeft,
18 CCDeviceOrientationLandscapeRight = kCCDeviceOrientationLandscapeRight,
19 } ccDeviceOrientation;

根据注释所说,肖像模式是设备为垂直方向的,home键在下方。想象一下手机,这个不难理解。

如何设置设备的方向呢?

在cocos2d-x上我们通过CCDirector的getDeviceOrientation获取设备方向,setDeviceOrientation设置设备方向。但如果是在Win32平台上就要特别对待。请看:

 1 ccDeviceOrientation CCDirector::getDeviceOrientation(void)
2 {
3 return m_eDeviceOrientation;
4 }
5
6 void CCDirector::setDeviceOrientation(ccDeviceOrientation kDeviceOrientation)
7 {
8 ccDeviceOrientation eNewOrientation;
9
10 eNewOrientation = (ccDeviceOrientation)CCApplication::sharedApplication().setOrientation(
11 (CCApplication::Orientation)kDeviceOrientation);
12
13 if (m_eDeviceOrientation != eNewOrientation)
14 {
15 m_eDeviceOrientation = eNewOrientation;
16 }
17 else
18 {
19 // this logic is only run on win32 now
20 // On win32,the return value of CCApplication::setDeviceOrientation is always kCCDeviceOrientationPortrait
21 // So,we should calculate the Projection and window size again.
22 m_obWinSizeInPoints = m_pobOpenGLView->getSize();
23 m_obWinSizeInPixels = CCSizeMake(m_obWinSizeInPoints.width * m_fContentScaleFactor,
m_obWinSizeInPoints.height * m_fContentScaleFactor);
24 setProjection(m_eProjection);
25 }
26 }

大家可以注意到在Win32平台上,setDeviceOrientation并不更新m_eDeviceOrientation,所以m_eDeviceOrientation总是保持他的默认值——CCDeviceOrientationPortrait。也就是说getDeviceOrientation的返回值总是CCDeviceOrientationPortrait。

那么在Win32平台上如何设置设备方向呢?来看下模板为我们生成的初始化代码:

 1 bool AppDelegate::initInstance()
2 {
3 bool bRet = false;
4 do
5 {
6 #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
7
8 // Initialize OpenGLView instance, that release by CCDirector when application terminate.
9 // The HelloWorld is designed as HVGA.
10 CCEGLView * pMainWnd = new CCEGLView();
11 CC_BREAK_IF(! pMainWnd
12 || ! pMainWnd->Create(TEXT("cocos2d: Hello World"), 480, 320));
13
14 #endif // CC_PLATFORM_WIN32
15 bRet = true;
16 } while (0);
17 return bRet;
18 }

根据前面的知识我们可以推断出,这是一个风景模式的HVGA窗口。如果想要将他变为肖像模式,只需要将宽度(480)与高度(320)参数对调。这是目前来说最简单,最有效,甚至可以说是唯一可行的方案。

如果要在iOS或者android上设置设备方向,我只能建议你去看一下 http://www.cocos2d-x.org/projects/cocos2d-x/wiki/About_device_orientation

转载于:https://www.cnblogs.com/cocos2d-x/archive/2012/02/28/2371429.html

### ESP32 Arduino框架驱动1.69寸LCD屏显示教程 #### 准备工作 为了使ESP32能够在Arduino框架下成功驱动1.69英寸的LCD显示屏,需先确保已正确安装了Arduino IDE并配置好了ESP32的支持环境[^2]。 #### 库文件准备 针对特定型号的LCD屏幕(如1.69英寸),通常需要下载对应的库来支持其操作。对于该尺寸的TFT液晶显示器来说,常用的库有`Adafruit_GFX`和`Adafruit_ST7735`或类似的专用于ST7735控制器芯片的库。这些库提供了初始化屏幕、绘制图形以及文字等功能的方法。 #### 初始化设置 在代码中引入必要的头文件之后,定义与屏幕通信所需的引脚编号,并调用相应的函数完成屏幕的初始化过程: ```cpp #include <SPI.h> #include <Adafruit_GFX.h> // Core graphics library #include <Adafruit_ST7735.h> // Hardware-specific library for ST7735 screens #define TFT_CS 15 #define TFT_RST 27 #define TFT_DC 33 #define TFT_MOSI 23 #define TFT_SCLK 18 // Initialize the screen with custom width and height parameters matching your specific model. Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST); void setup(void) { Serial.begin(115200); // Begin initialization of the display module tft.initR(INITR_BLACKTAB); // Initialization command sequence // Set orientation (landscape or portrait mode) tft.setRotation(1); // Landscape orientation // Clear screen to a solid color as needed tft.fillScreen(ST77XX_WHITE); } ``` 此部分代码完成了对指定大小LCD屏幕的基本设定,包括但不限于颜色模式的选择、旋转方向调整等[^3]。 #### 显示图像实例 当涉及到具体的图像展示时,则可以根据实际需求加载位图或其他格式的数据到屏幕上。下面给出了一段简单的例子用来循环播放三张预存于SD卡中的JPEG图片: ```cpp String ImagePath[] = {"../pic/LCD_1inch69_4.jpg", "../pic/LCD_1inch69_5.jpg", "../pic/LCD_1inch69_6.jpg"}; for(int i=0;i<3;i++){ File imgFile = SPIFFS.open(ImagePath[i], "r"); if(!imgFile){ Serial.println("Failed to open image file."); continue; } uint32_t startTime = millis(); while(imgFile.available()){ byte data = imgFile.read(); // Assuming there is an appropriate function to handle JPEG decoding here... decodeJpeg(data); if(millis()-startTime > 2000){break;} // Limit each frame's duration to about two seconds } imgFile.close(); } tft.drawBitmap(xOffset,yOffset,width,height,imageBuffer); // Draw decoded bitmap onto screen at specified coordinates delay(2000); // Wait before switching next picture ``` 请注意上述示例假设存在一个名为`decodeJpeg()`的功能来进行JPEG解码处理;而在真实环境中可能需要用到第三方库比如`jpegdec`来实现这一目的。另外,在执行绘图命令之前应当计算好目标位置(`xOffset`,`yOffset`)及所需缩放后的宽高参数(`width`, `height`)以便适配当前设备分辨率的要求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值