Creating the project and displaying the first object

Starting from this section, we will start to learn the development foundation and operation of Cocos Creator in detail. Let's first create a project, open CocosDashboard, select "New", select the 3D game template "Empty(3D)", enter the name of the project (classGame) and the path (D:\Home\workspace), (note that the name of the project does not need to be Use Chinese characters and spaces, use English abbreviations, and the project path should not be too deep, otherwise an error may be reported when packaging and publishing), click "Create" to create and generate a standard 3D empty project. 

After the creation is completed, Cocos Creator will open the project we just created, so that we can develop games based on Cocos Creator. First of all, we need to divide the following project development folders to classify the files and resources in game development. Generally, we will divide them into three categories: game resources, game scenes, and game code. Usually we use some conventional names, such as AssetsPackage for game resources, Scenes for game scenes, and Scripts for game code. Of course, you can name them according to your own habits, but you must not use Chinese + spaces here. As shown below, we first classify the Assets folder:

AssetsPackage: used to store game resources;

Scripts: used to store the business logic code of the game;

Scenes: used to store game scenes; 

After the creation is completed, let's look at the changes in the project. Open the folder where the project is located, right-click on "asset" and select "Show in Explorer". "Assets" in the hierarchy manager corresponds to the project project folder assets.

The AssetsPackage, Scrtips, and Scenes just created in the hierarchy manager are also under the asset folder, as shown in the figure:

Internal in the hierarchy manager refers to the resources and files inside the engine. Right-click on "internal" and select "Show in Resource Manager" to open the resource folder path inside the engine, as shown in the figure:

Create a game scene

After the Assets folder is divided, we first create a scene. What is a game scene? We can understand it as a container. All objects to be rendered by the game engine must be placed in this container, so we need to create one or more such containers to hold game objects. So the game scene is a container for storing game objects . When we develop a game, to display an object is to create an object into the game scene. To create objects into the game scene, we can drag them directly through the editor or create them through code. We will explain them in more depth later. Now, let’s drag some objects through the editor and place them in the game scene.

If the currently opened scene does not have a corresponding scene file saved (just like opening word, it is not currently saved as a corresponding word file). If we save it directly with ctrl+s, we will be prompted to save the scene file. We enter the name of the scene, and then You can create a scene. Proceed as follows:

Ctrl+s saves the following currently unsaved scenes:

In this way, the main scene is created. If the current edited scene already has a corresponding scene file, and we want to create a new scene, we can create a scene through the menu "File/New Scene", and then repeat the above steps ctrl+s to save the current scene to a file, so , and a new scene is created. Every time the project is opened, the scene content edited last time is saved to the scene file, so it will still be there next time it is opened.

  After creating a scene, there are two objects in the scene by default, one is the parallel light source Main Light, and the other is the camera Main Camera. The parallel light source can provide light source for the game world, and the camera is used to shoot the game screen. The game screen we see is all It is "shot" from the perspective of the camera and then displayed on the screen, so if there is no camera, we cannot display the picture.

2.3Create and display the first 3D object

  After the scene is created, we create a 3D object into the game scene. The game engine has some standard geometries built in, such as cube (Cube), sphere (Sphere), etc., so we first create the geometry and display it in the scene. Let's create A Cube, in the scene editor, right-click "Create/3D Object/Cube Cube", a Cube node will be created in the scene, ctrl + s to save the following current scene changes, double-click the following current "Cube" node, so that the center of the editor will align with the Cube object just created, as shown in the figure below

Click the camera node in the scene, and there will be a small window of camera effect preview in the lower right corner of the editor, indicating the effect of the picture captured by the camera. This effect will be displayed on the screen device. As shown below:

Game preview running

  After developing some projects and functions, we need to run the effects and debug the program. We can use cocos creator to preview and run the project directly.

Select the preview mode. There are three modes: "browser preview, editor preview, and simulator preview". Generally, I choose browser preview, as shown in the figure: 

Select the game scene to be previewed and click the drop-down box. The "Current Scene" and the scenes in the current project will be displayed. Which one you want to preview can be selected. Generally, we select " Current Scene " so that you can edit it. Which scene is the preview running?

  1. Click Run. Click the Run button to preview the run. Effect,

  1. When previewing and running on a mobile phone, Cocos Creator will assume a webserver based on the local area network, and then generate an http connection barcode. Scan the code with your mobile phone to preview and run the game on your mobile phone, but the premise is that the mobile phone and computer use the same local area network. As shown below

Guess you like

Origin blog.csdn.net/Unity_RAIN/article/details/134579187