Cocos2dx portrait screen setting in xcode5

Source: Internet
Author: User

One thing we will always consider before developing a game is whether our game supports horizontal screen, vertical screen, or landscape screen. So how to set the project in xcode? In xcode5.1.1, I will use cocos2dx2.2.3 to set the game landscape and landscape from the creation of a new project.

 

1. Create a project

Find the corresponding directory of cocos2dx, use the Python script to create a project, and enter the following command on the Mac terminal (here is my directory location, the project name and package name are named randomly ):

CD/cocos2d-x-2.2.3/tools/Project-creatorpython create_project.py-Project name-package name-language CPP

The project is successfully created. In the cocos2d-x-2.2.3 directory, open the projects directory, find the new project, enter the project directory will see the following directory structure, because we are in the MAC system development, open the corresponding IOS directory and find the project file to open

 

Ii. Landscape and vertical Screen Settings

After opening the project, you can set up a virtual machine in the upper-left corner of xcode (the iPhone device needs to be downloaded on its own, as described in the previous blog)

Compile and run the program after setting the virtual machine.

The running result shows that the new project is displayed on a horizontal screen by default. After the device is rotated to a portrait screen, the game screen is not automatically rotated.

Rotate the device 90 degrees, and the game screen automatically changes

Next, let's take a look at how to set the device direction.

First, click our project, select the "General" tab, and find "device orientation" under "deployment Info". There are four options. Currently, the following two options are selected, that is, the result we see above shows the two statuses of the device on the horizontal screen.

It should be better understood if it corresponds to the previous version of xcode

When only one direction is set, after the device is rotated, the game screen will only be displayed in the set direction. when the device is rotated to another direction, the game screen will not rotate on its own.

Now, we set the device direction to the two options above and the two directions of the portrait screen.

Run the program now and you can see the following effect: the game screen has changed to a portrait screen.

After the device is rotated to a horizontal screen, the effect is as follows: The game screen is not rotated

Then rotate it 90 degrees, as shown in figure

At this time, the game screen is not automatically rotated, which is inconsistent with our settings. Now, we only set the device direction to "upside down", that is

When running the program, we will see that the program throws an exception

Now we need to modify the code and find the "rootviewcontroller. MM" file in the IOS directory of the project.

We find the supportedinterfaceorientations method, and we can see the end of the returned value here, we will know why the above exception occurs.

In the header file "uiapplication. H", we can view the meaning of the returned value (at the bottom). The meaning should be better understood.

Now we change the returned value to all directions.

Run the program. At this time, the device direction is consistent with the game screen and our settings.

We found in "rootviewcontroller. the "shouldautorotatetointerfaceorientation" method in MM also seems to be related to the screen direction. However, when we see the above annotations, we know that this method is no longer used in ios6, however, you still need to set the version before ios6.

In fact, the return value of this function is relatively simple. Similarly, in "uiapplication. H", you can set it as needed.

To sum up, we need to set three places when setting the game picture direction.

(1) "device orientation" option under the "General" tab of the project

(2) Return Value of the "supportedinterfaceorientations" function of "rootviewcontroller. MM" in the IOS directory of the project

(3) Return Value of the "shouldautorotatetointerfaceorientation" function in "rootviewcontroller. mm"

Now, we can set the game support landscape or landscape screen based on the needs of our project.

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.