Previous Next |
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 app developer to construct a single image from smaller individual images. The game package also provides a layer manager for apps that use multiple layers or that have layers larger than the device screen. SpritesA sprite is an image comprised of frames (smaller images). When an app draws a sprite, it draws one of the frames. An app can show different frames in a sequence to animate the sprite. The sprites in MIDP also provide transformations, such as mirroring, and collision detection. app 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 app 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 Screenshot. Screenshot Positioning a SpriteBy contrast, setting a reference around which to transform a sprite requires an app developer to provide an x and a y value, but the values define the position of a reference pixel, as shown in Screenshot, not a point. Screenshot A Sprite's Reference PixelAnother feature of sprites is collision detection, which takes place within a collision rectangle. By default the rectangle is the entire sprite, but the app 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. app Developers
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 app developer. Screenshot shows how tiles can be written to a tiled layer to form a larger picture. Screenshot Tiled Layer and TilesUsing 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. app Developers
|
Previous Next |