Landscape or portrait

Source: Internet
Author: User

OurProgramIs it landscape or portrait? How do I set up when using a cocos2d-x for development on the Win32 platform? It is necessary to clarify these issues before continuing the following tutorial.

What is Landscape mode? What is the portrait mode?

According to my understanding, the width is greater than the height and has a wider field of view. It is suitable for enjoying the scenery. The height is greater than the width, which can provide a close-up for standing characters and is suitable for painting portraits.

In cocos2d-xCodeThe device direction is defined as follows:

 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;

According to the comment, the portrait mode is vertical to the device, and the home key is below. Imagine a mobile phone.

How do I set the device direction?

On the cocos2d-x, we get the device direction through getdeviceorientation of ccdirector, and setdeviceorientation sets the device direction. However, if it is on the Win32 platform, it should be specially treated. See:

 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 shoshould 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 }

You can note that on the Win32 platform, setdeviceorientation does not update m_edeviceorientation, so m_edeviceorientation always maintains its default value-ccdeviceorientationportrait. That is to say, the return value of getdeviceorientation is always ccdeviceorientationportrait.

On the Win32 platform, how does one set the device direction? Let's take a look at the initialization code generated by the template:

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 }

Based on the previous knowledge, we can infer that this is a scenic hvga window. If you want to change him to portrait mode, you only need to adjust the width (480) and height (320) parameters. This is the simplest, most effective, and even the only feasible solution.

If you want to set the device direction on iOS or Android, I only recommend that you look at the http://www.cocos2d-x.org/projects/cocos2d-x/wiki/About_device_orientation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.