The art of mobile game architecture

Source: Internet
Author: User
Tags xml parser

Http://innovator.samsungmobile.com/cn/bbs/discussion/view.do? BoardId = 913 & boardName = pick_WM & messageId = 109578 & messageNumber = & messageCategoryId = 0 & startId = zzzzzzz ~ & Amp; startPage = 1 & curPage = 1 & rowsPerPage = 10 & searchType = title & searchText = & searchDays = 0 & searchTitleFlag = false & searchContentsFlag = false & searchRegisterNicknameFlag = false & lastPageFlag = & Categ = 382 & parentCategoryId = 218 & platformId = 2 & selectOrder = REGISTER_DATE & selectOrderDirection = DESC & searchParameters =/cn/bbs/discussion/thread. list. do % 3 FlistLines % 3D10 | searchType % 3

Author: Yang rich, manager of Qingling digital R & D department, proficient in Java, C/C ++, and other languages and platforms such as j2-brew, MTK, Android, and iPhone. He once led and participated in the development of games such as legend of the Three Kingdoms and Legend of the sea. The secrets of Android application development.

Art is an organic product of comprehensive psychological activities of people's knowledge, emotions, ideals, and ideas. It is an image of people's real life and spiritual world. Literature can be art, sculpture can be art, music can be art, movies can be art ...... What about games?

Game is a comprehensive art

Both stand-alone games, online games, PC games, and mobile games must go through the step-by-step evolution process shown in step 1.

Figure 1 game R & D process

Any game has content such as the story, characters, scenes, music, and sound effects. Therefore, each part of the content must be artistic, presents the image scenarios of the game to users more vividly. As a programmer, we may have previously thought that only planners need to express the game content through art, and testers need to enjoy and improve the game experience with art, so how can programmers hook up with the game architecture and art?

The sword of casting art in Programming Language

Since ancient times, many people have been keen on sword casting. The key to whether a sword can be regarded as an artistic work is whether it can express the emotions and intentions of the swordsman. The architecture of game programs also needs to reflect the architect's grasp of the overall architecture and each module of the game, as well as the "power" granted to them. At the same time, A good architecture also runs through the entire game development process. After a simple test, do you also encounter the following problems?

I feel like the game framework is messy and unorganized?
After the development is complete, there are a lot of bugs and I don't know how to solve them?
Are there many fatal bugs that are hard to reproduce?
Is it very difficult to add a function or module?
After frequent changes, a large number of redundant code occurs?

If the above problem occurs, it means that the architecture sword we use is not sharp, and we may not use the "force" on the blade. This also reflects the importance of the sword Casting Process (that is, the architecture of the game. If you continue to exercise these questions, you will eventually become a peerless sword.

Architecture is an illusory thing that cannot be seen or touched. Therefore, we analyze how to artistic architecture and express architecture ideas through code based on specific instances. Let us assume that there is a planning case, and the artist can prepare the required resources for us.

"Mining" is the foundation of sword Casting

With the idea of casting a sword, you need to choose a variety of high-quality Xuan iron ore. Similarly, for the game architecture, it is necessary to analyze each function module of the game and abstract the functions and special attributes that each module needs to implement, summarize the data structures and interfaces to be defined by each module and the relationships between modules. Then, sort out the flowchart, relationship diagram, and structure diagram suitable for programming based on the planning documents. Finally, based on these documents and materials, the game operating environment (such as the game running platform) needs to analyze the implementation technology. This analysis mainly targets the functions and performance. The following uses the Android and iPhone platforms as examples. On the Android platform, from the perspective of efficiency, you can select C/C ++ as the development language and OpenGL | ES as the graphics library. In terms of simplicity and convenience, you can select Java as the development language and Skia as the graphics library. On the iPhone platform, you can choose C/C ++ as the development language and OpenGL | ES as the graphics library from a cross-platform perspective. Considering the difficulty of development, you can select Objective-C as the development language and Quartz2D as the graphics library. Here we do not consider the special issues of 3D. If we develop 3D games, we will inevitably choose OpenGL | ES. In addition, the use of Quartz2D as a graphics library on the iPhone platform is rarely used to develop games.

For a cross-platform game, we also need to analyze the cross-platform capabilities and features of each platform (including development languages, rendering libraries, resource management, and memory management ), for example, if the iPhone memory management uses the reference counting mechanism, you can consider using C ++ to implement a similar mechanism, so that other platforms can also use this mechanism.

Here we have not deliberately compared a language and a library, because they usually have their own advantages and need to be selected based on specific game needs. After you have prepared Xuan tie for the sword casting, will we start to build the sword (write code) next?

"Jian fan" decides "Jian Qi"

"Jian fan" refers to the model used to build a sword, and "Jian Qi" refers to the momentum of the sword product. Therefore, the model used to build a sword will ultimately determine the "topic" of the sword ".

The creation of "jian fan" corresponds to the core framework responsible for the global scope in the game architecture. Whether the framework is reasonable or not determines the success or failure of the entire architecture. Speaking of the framework, I have to say that everyone may be familiar with the MVC framework. As a programmer, no one should know the definition of MVC, but the key lies in how to learn it from a deeper level and understand it, run it. A friend once asked me, "What framework do you usually use? What framework will be better ?" I replied, "What is the MVC Framework !" He looked at his surprised face and said, "It's also a very common framework !" I really don't know what to say! The MVC framework is really common and simple, but how to make it play its own role is the key! For example, in iPhone development, Apple recommends this framework, which is described as follows:

View (V): it is provided by the subclass of the UIView class and its related UIView-Controller class;
Controller (C): The Controller behavior is mainly implemented by delegation, target operations, and notifications;
Model (M): provides logical models through protocols such as databases and data definitions, which are managed by controllers.

In addition, even for Android systems that are currently on the internet, Google also recommends using the MVC framework to develop and maintain applications. The specific descriptions are as follows:

View (V): The View and SurfaceView (or custom View) provide the user interface and adopt the XML format for layout;
Controller (C): Views and logical models are managed by Activity;
Model (M): provides a logical model to a view, which is triggered by a controller, for example, a variety of Adapter interfaces.

Based on my personal experience, I came up with the following point: "If you cannot ensure that other design patterns are well applied, it is better to choose a simple and non-simple framework like MVC, the results may be even better!"

This shows the importance of frameworks in game architectures. If you still don't think it is enough, I suggest you ask a large number of Android and iPhone developers for the answer. Apple and Google Documents will be your best learning materials! I believe that you have followed our steps to create a "Sword fan" suitable for you. Now is the time to build a sword!

Not afraid of fire

The quality of baojian lies in the raw materials used. How can we check the material of ore? It depends on whether the firepower to be prepared is strong. Now let's go back to the topic of game architecture.

First, although a game may have multiple views, multiple models, or even multiple controllers, we divide the game into three major modules, that is, the Controller, view, and logic model of MVC.

Figure 2 shows the framework of an Android game I am currently developing.

As shown in figure 2, the program enters from the entry Activity. When the setContentView () function is used to display a view MainView class, the main thread of the game has started Loop; the specific scenario for the game to be displayed is obtained by the controller Control class through the getCurScene () function based on game status and other information. The resulting scenario is actually a subclass of the SceneInterface class (such as SceneA) of the abstract scenario ); in SceneInterface, public interfaces for various scenarios are included to facilitate Control. control () can directly control the current display scenario. Note that in the controller, SceneInterface is usually used first. reCycle () to reCycle the garbage generated on the previous interface, and process the data in the logical Model.

Because of the image size, I did not list all the class structures, these classes include defining a public interface for an interface event in SceneInterface or extending the Model using the "entity-object-class" method and the required tool classes.

The highest realm of sword casting-the person who guides the sword

A good sword can usually improve the sword skill of the man who uses it! The two swords Android and iPhone built by Google and Apple have guided countless developers. Why don't we learn how to learn the skills of the two swordsmen Google and apple?

Next, we will continue to analyze how Android may guide "jian Jian ren ". When developing Android applications, Google recommends layout interfaces using XML files to separate the UI interface from program logic for easy maintenance; in fact, Google has optimized XML files and other resources to improve program running efficiency. Next we will also learn this trick and use XML files to deploy game scenarios.

First, the content to be displayed in a game scenario (SceneA) is divided into two parts: the UI interface (such as buttons, menus, etc.) and the game object (such as Genie). Second, the UI interface and Game objects may both require animation. Finally, a dedicated parser is required to use XML files for layout. For more information, see Module 3.

Figure 3 game scenario Architecture

Figure 3 describes the element architecture and parsing of a scenario. The UI interface, Game objects, and animation modules all use one or more XML files, finally, the content of the XML file is output to SceneA. The whole process requires an XML parser, and then various types of UI controls, Game objects, and animations are constructed based on the game's needs. Currently, the following classes are used in the project:
U I Controller: u I Te x t, u I P r o g r e s, UITexture, UIList, UIClick, UICheckBox
Game objects: GameObj, javastobj, Bullet, and Enemy
Game animation: PosAnimation, ColorAnima-tion, FrameAnimation

Each class has its required member variables. Next we can use the XML file to layout the game scenario based on the parser implementation. Based on the needs of the game, you can expand the XML file to support multi-level sub-nodes, and then obtain the elements defined in XML in the game for operations. You also need to analyze the interface and program to facilitate modification and maintenance. The entire process is shown in step 4.

Figure 4 XML Layout Process

In fact, my ongoing project not only encapsulates the three modules mentioned above, but also encapsulates the entire game architecture, including the controller, main thread, and model shown in figure 2, the entire framework can be directly written through an XML file. Here, the sword you created should also be born. Take it with you and rush to the game world.

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.