IPhone game development tutorial game engine (2)

Source: Internet
Author: User

IPhone gamesDevelopment tutorialGame Engine2) It is the content to be introduced in this article. Continue to understand the content in the previous chapter. If you want to learn more, please follow the end. This section describesGamesSome elements used in the development process are described first.

Image Engine

ImageEngineResponsible for visual output, including graphical user interface GUI for user interaction) objects, 2D genie animations or 3D model animations, and rendering background and special effects.

Although the technology for rendering 2D and 3D images is different, they all complete the same set of graphics tasks, including textures and animations, and their complexity increases.

Texture

For the displayed image, the texture is center. In 2D, a flat image is displayed on the screen in pixels, while in 3D, a group of triangular rows or grid is called) creates a flat image and displays it on the screen. After that, everything will become complicated.

Pixels, textures, and images

The basic unit for screen plotting is pixels. Each pixel can be broken down into red, green, and Blue values and the Alpha values we will discuss right away.

Texture is a set of data about rendering a set of pixels. It contains the color data of each pixel.

An image is a higher level concept. It is not associated with a set of special pixels and textures. When a person sees a group of pixels, his brain combines them into a picture. For example, if the pixels are represented in the correct order, he may see a picture of a giraffe.

It is necessary to keep these concepts independent. A texture may contain pixels that make up a giraffe image: it may contain enough pixels to make up multiple images of a giraffe, or only contain pixels that make up a giraffe image. Texture itself is a set of pixels, and it does not necessarily know that it contains an image.

Transparency

At any moment, your game will have several or more objects rendered on the screen, some of which will overlap with another. The question is, how can we know which pixel of an object should be rendered?

If the texture on the top is traced after another texture) is completely opaque, its pixels will be displayed. However, for game objects, non-rectangular images and some transparent objects may cause the combination of the two textures.

The most common mixing method in 2D images is completely transparent. Suppose we want to draw a koala Image 2-3) crawling on top of Eucalyptus 2-4. Koala images are stored in memory as rectangular textures, but we don't want to draw the entire rectangle. We just want to draw the pixels of the koala body. We must determine whether each pixel in the texture should be displayed.

Figure 2-3 koala texture

Figure 2-4 eucalyptus texture

Some Image Systems Add a mask to achieve the goal. Imagine that we have another texture in the memory of the same size as the koala texture, which only contains white and black pixels. Each white pixel in the mask represents the pixel that the koala should draw. The black pixel in the mask represents the pixel that should not be drawn. If we have such a mask layer when we draw a koala onto the screen, we can check the pixels corresponding to the koala and only represent the pixels to be drawn. If each pixel allows a set of range values instead of binary black/white values, it also supports partial transparency, see Figure 2-5 ).

Figure 2-5 koala mask texture

Texture Mixing

The storage capacity prepared for textures is large enough to support a range value for each pixel. Typically, an Alpha value occupies one byte, that is, a value between 0 and 25 is allowed. By merging two pixels, You can see interesting visual effects. This effect is usually used for partial transparency, for example, partial or full-view object graph 2-6 ).

Figure 2-6 transparent green rectangles

We can set Alpha for each pixel to determine how they are mixed. If the range of a pixel is 0-255, the range of Alpha should also be 0-255. Although the red value is 0, it indicates that red should not be used for plotting, but the Alpha value is 0, it indicates that the pixel should not be painted at all. Similarly, the red value of 128 indicates that half of the maximum Red value should be used for plotting, and the Alpha value of 128 indicates that half of the color value of this pixel should be used when mixing with another pixel.

It is important to correctly arrange the object sequence when a hybrid object is created. Because each mixed rendering action only renders the source object and the target object, the first tracked object will not be mixed with the latter. Although this is easy to control in 2D images, it becomes very complex in 3D images.

Rotate

In 2D images, most textures are directly rendered to the target without rotation. This is because the standard hardware does not have the rotation function, so the rotation must be calculated in the software. This is a very slow process, and it is easy to produce low quality pictures.

In general, game developers pre-render the image of an object in all directions, and when the object is in a certain direction, draw a correct picture on the screen to avoid the above problems.

In 3D images, rotation is calculated in the same way as lighting, and is part of the hardware rendering process.

Clipboard

Due to some reasons explained in the following sections, another important aspect of texture is clipboard. Although our current example is to directly describe the source texture to the target texture, it is often possible to describe some source textures to a limited part of the target texture.

For example, if your source texture contains multiple images in a file, cropping allows you to render only the part you want to draw.

The clipboard also allows you to draw a small part of the target texture. It allows you to use texture ing to render objects in 3D mode and overlay the texture to any shape mesh composed of triangles. For example, a texture can represent clothing or animal fur, and a 3D role may fold after moving it. Texture is usually called skin at this time.

Summary:IPhone gamesDevelopment tutorialGame Engine2) I hope this article will help you! Want to learn moreGame EngineFor more information, see the following articles:

IPhone game development tutorial Game Engine 1)

IPhone game development tutorial Game Engine 3)

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.