IPhone game development tutorial game engine (3)

Source: Internet
Author: User

IPhone gamesDevelopment tutorialGamesEngine 3) is the content to be introduced in this article. Continue with the content in the previous chapter. This article mainly introducesAnimationFor more information, see the content.

Animation

By rendering continuous images, we can ensure that the player sees a moving object. Although all he does is on the same pixel, These pixels are changing the color quickly. This isAnimation. 2DAnimationSimple, but 3DAnimationIt usually involves more objects and actions, so it is more complicated.

Besides DiscussionAnimationTip, this section also discusses the main types of optimization that make our image engine efficiently and reliably complete complex graphics tasks that are not completed in the original way. Some major optimization techniques include elimination, texture sorting, intelligent texture File Usage, resource management, and detail level rendering.

2D animation: genie

In 2D images, if we want to render the complete scenario of Mercedes Benz, We can first create pictures of Mercedes Benz's different postures. This image is a frame. When one frame after another is rendered to the screen, the horse moves, as shown in Figure 2-7 ). This is very similar to how a movie creates an animation. A movie moves by displaying Consecutive Frames.

Figure 2-7 actions of Stanford's horse

To save these frames together, we place them in the same texture, called the genie. Based on the cropping method described in the previous section, only the content of the current frame is rendered to the screen.

You can render each frame multiple times until the next frame of the sequence is rendered. It depends on how fast you want your animation to play and how many frames are provided. In fact, you can create multiple effects by rendering the frame speed and sequence.

3D animation: Model

Unlike the sprite, which is used for rendering each time a 3D animation is re-painted, 3D animation computes the geometric Effect of motion through actual computation. As we described earlier, all 3D objects are composed of one or more triangles, called grids. There are a variety of ways to make the grid work, these technologies are related to the development of the game and graphics hardware. The basic concepts behind these technologies are: key frames.

The key frame is somewhat different from the frame in the 2D animation we discussed earlier. The 2D animation artist draws each frame and saves it in the texture. But in 3D, as long as we save the most special frames, We can get other frames through mathematical computation.

The first game to use grid animation actually stores multiple copies of the grid, and each copy is in different key frame directions. For example, if we render a trojan in 3D, we should create a grid for each key frame of the genie above. In time (1), the first frame is illustrated. In time (2), the second frame is described.

A technique called interpolation is used between key frames. Because we know that the key frames of time (1) have the same number of triangles as the key frames of time (2), but the direction is slightly different. We can create a temporary key at the current time point, integrates the mesh of the first two grids. So in time (1.5), the temporary mesh looks exactly between time (1) and time (2), while in time (1.8), it looks more inclined to time (2 ).

The reason for the low technical efficiency is obvious. It is acceptable only when there are a few triangles and a few key frames, but modern images require animations with high resolution and vivid details. Fortunately, there are better ways to store key frame data.

This technology is called "skeleton animation" skeletal animation, or bone rigging ). Take Ma Er as an example. You may notice that most triangles are moved in groups, such as the head group, tail group, and limbs group. If you think of them as a bone Association, then these bones are combined to form a bone.

A bone consists of a group of bones that can be applied to a grid. An animation is formed when a group of bones are continuously expressed in different directions. Each frame of animation uses the same grid, but there will be small changes in the movement of the bone from the front side to the next position.

You can create a temporary mesh and render it to the screen by storing it only in a grid of a certain position and using it at every key frame. By interpolation between two key frames, we can create the same animation at a lower cost.

Animation Controller

The animation controller object is very useful in abstract low-level tasks, such as which frame to render, how long to render, And the next frame to replace the previous frame. It also serves to connect game logic and animation-related parts such as image engines.

On the top layer, the game logic only cares about setting something, such as playing a running animation, and setting its speed to be possible to run several units per second. The Controller object knows which frame sequence corresponds to the running animation and the playback speed of these frames, so the game logic does not need to know these.

Particle System

Another useful object similar to the animation controller is the Particle System Manager. Particle systems can be used to describe highly fragmented elements, such as flame, cloud particles, and flame tail. Although each object in the particle system has limited details and animations, they can be combined to form entertaining visual effects.

Elimination

The best way to increase the number of times the image is to reduce the total number of times the image is drawn on the screen in each iteration. Your scenario may have hundreds of objects at the same time, but if you only need to describe a small part of it, you can still render the screen very quickly.

Elimination removes unnecessary objects from the drawing path. You can perform elimination at multiple levels at the same time. For example, at a high level, a user cannot see objects in the next room in a closed room, so you do not have to draw other objects next door.

At a low level, the 3D image engine often removes some of the grids you draw from them. For example, at any suitable given point in time, half of the mesh ry is on the back of the camera. You cannot see these grids from the camera, but only the mesh in front of the camera. Therefore, when the mesh is rendered, all the grids behind the camera will be ignored. This is called backend elimination.

Texture sorting

Each time an object is rendered to the screen, the graphic hardware loads the texture source file into the memory. This is part of context switching.

If you want to describe three images to the screen, and two of them share the same texture resource, there are two ways to deal with texture sorting: an Efficient Method is to render two images with shared resources consecutively. In this way, only the context needs to be exchanged, while an inefficient method requires two context exchanges. You should not describe the third image between two images with shared textures.

During rendering, objects with shared textures can be arranged to reduce the number of context exchanges and increase the rendering speed.

Texture File

You can plan the texture structure at the beginning to help you arrange your textures in an optimal way. Suppose you are going to draw ry, a main character and some creatures in your game.

If the first two levels are lawns and the next level is desert, you can put images of all the trees, grass, shrubs, rocks, and flowers together to render the first two levels, place the sand image in another texture file to render the third level. Similarly, you can place a virtual player doll in a texture. If all creatures are used in all levels, the best way is to place them in a texture file. However, if the first level contains the monkey and the second level only the forest rat and Suriname toad, you can put the first two animals in a texture, place the last two in one texture.

Resource management

Most videosGamesAt a time point, only a small part of all their images will be rendered. It is very inefficient to load all textures into the memory at the same time.

Fortunately,GamesThe design usually determines which resources areGamesAre visible. By retaining the required textures as the loading state and uninstalling unused textures, the limited memory resources can be used most effectively.

Use the example in the previous section.GamesWhen the engine loads the first level, the Resource Management Code must ensure that the texture of the monkey and the mouse is loaded into the memory. When the program goes to the next level, the Resource Management Code will unmount those textures because it knows they will not be used in the second level.

Level of detail

Another optimization technique, especially for 3D images, is called the level of detail. Consider that when an object is away from the camera, it looks very small and most of the details are lost. You can draw an object of the same size but only has a simple grid, or even a plane map.

By keeping copies of objects of different levels of detail in the memory, the image engine can decide which copy to use based on the distance from the camera.

Summary:IPhone gameDrama development tutorialGamesEngine 3). I hope this article will help you! Want to learn moreIPhone gamesFor more information about the engine, see the following articles:

IPhone game development tutorial Game Engine 1)

IPhone game development tutorial Game Engine 2)

IPhone game development tutorial game engine 4)

IPhone game development tutorial game engine 5)

IPhone game development tutorial Game Engine 6)

Related Article

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.