| [ directory ] |
|
11.3 LayersIn addition to the game canvas, the game package provides layers, which are basic visual elements on a game screen. One type of layer is a sprite. Another type is a tiled layer, which enables an application developer to construct a single image from smaller individual images. The game package also provides a layer manager for applications that use multiple layers or that have layers larger than the device screen. 11.3.1 SpritesA sprite is an image comprised of frames (smaller images). When an application draws a sprite, it draws one of the frames. An application can show different frames in a sequence to animate the sprite. The sprites in MIDP also provide transformations, such as mirroring, and collision detection. Application Developer
Sprites provide transformations such as rotating 90 degrees. They provide the concept of a reference pixel so that the transformations can appear to be taking place around a certain place in the sprite.
When an application developer positions a sprite at an initial x and y point, the point sets the location of the upper-left corner of the sprite's visual bounds. It puts the sprite's top, left pixel at the pixel below and to the right of the (x,y) position on the canvas, as shown in Figure 11.1. Figure 11.1. Positioning a Sprite
By contrast, setting a reference around which to transform a sprite requires an application developer to provide an x and a y value, but the values define the position of a reference pixel, as shown in Figure 11.2, not a point. Figure 11.2. A Sprite's Reference Pixel
Another feature of sprites is collision detection, which takes place within a collision rectangle. By default the rectangle is the entire sprite, but the application developer can make the rectangle smaller or larger. Collision detection checks for an intersection between the collision rectangle and an image, a nonempty tile in a tiled layer, or another sprite. Collision detection can also be done at the pixel level. In this case, the algorithm checks for collisions using only opaque pixels in the collision rectangle and the other tile, sprite, or image. Application Developers
11.3.2 Tiled LayersTiled layers provide an alternative to using large images in games. A tiled layer is a graphic made up of individual rectangles, and a group of small images that are the same size as the rectangles. The individual tiles are written into the rectangle in the order specified by the application developer. Figure 11.3 shows how tiles can be written to a tiled layer to form a larger picture. Figure 11.3. Tiled Layer and Tiles
Using a few individual tiles over and over to form a picture allows a game to use fewer system resources than would be used by a single large graphic. Using tiles can minimize screen redrawing and require less storage space on the device than a large picture would. Application Developers
|
| [ directory ] |
|