站内搜索: 请输入搜索关键词
当前页面: 图书首页 > MIDP Style Guide for the Java 2 Platform, Micro Edition

MIDP Style Guide for the Java 2 Platform, Micro Edition

[ directory ] Previous Section Next Section

11.4 Layer Manager

A single screen can show multiple layers. For example, in Push Puzzle, the pusher is a simple tile, but it could be a sprite. If the pusher were a sprite, the screen would be made up of two layers: the background and the sprite. The game package includes a layer manager, which draws the individual layers onto the device screen.

11.4.1 Layer Ordering

The layer manager keeps the layers in an ordered list, and assigns the layers contiguous integers. The application developer can add and remove layers from the list. Layer zero is closest to the top; higher numbers are progressively further away.

MIDP Implementors

Strongly Recommend: graphics/bulb1_icon.gif If the application developer removes a layer from the middle of the list, renumber the remaining layers to keep them contiguous.

Strongly Recommend: graphics/bulb1_icon.gif Draw the layers onto the screen in order, beginning with the layers furthest from the user (the backgrounds) through the layer closest to the user (layer zero).

Application Developers

Strongly Recommend: graphics/bulb1_icon.gif Remember, when you use the layer manager, the order of your layers is important.

11.4.2 The View Window and Panning

The layer manager has a view window, which enables the application developer to choose which part of the layer is shown to the user. The ability to show only one part of a layer to the user at a time enables the application to use background panning. Figure 11.6 shows a game canvas using the view window; the user can see only part of the layer. The full canvas is shown in Figure 11.4, level two.

Figure 11.6. View Window Showing Part of a Game Canvas

graphics/11fig06.gif

Application Developers

Strongly Recommend: graphics/bulb1_icon.gif As you consider whether to use panning, keep the input mechanism of the device in mind. A phone with a joystick-style disk is easier for users to pan with than a phone with only a keypad.

Strongly Recommend: graphics/bulb1_icon.gif If you use a view window, make it as large as or smaller than the screen area being used. A view window that is larger than the visible screen may result in a computation that will not be used if the view window's content must be clipped to fit on the screen.

Strongly Recommend: graphics/bulb1_icon.gif If you use a view window, keep the size of the display and the size of the image you are panning in proportion. A large image on a small display could be annoying to pan in certain games, especially those in which the user is expected to move quickly around the display. A large image on a small display could also be a problem in games that involve remembering the layout of the display. The game in Figure 11.6 is such a game. Users can easily lose the game if they forget the layout of walls. Forgetting is easier if most of the image is out of sight.

    [ directory ] Previous Section Next Section