Sprite (computer graphics)

from Wikipedia, the free encyclopedia
Simple sprite

A sprite is a graphic object that is displayed by the graphics hardware over the background image or the remaining content of the screen display. The positioning is done completely by the graphics hardware. For example, most graphics cards provide a hardware sprite for the mouse pointer .

The name comes from the fact that a sprite moves on the screen, but cannot be found in the graphics memory, so it appears to be "spooky". Over time, however, the term has also expanded to include all objects that look like this, even if they are generated by software and are in the graphics memory.

Today, real sprite technology is obsolete, especially since computers are now fast enough to easily display thousands of sprite-like objects on the screen and at the same time restore the background to its original form. The storage space required for this has also become less important.

Related terms

Multiple shapes in one block

The term sprite is often used in general terms for objects that are displayed over the background using software (instead of graphics hardware). Strictly speaking, however, this is a shape that is usually also referred to as a "software sprite". The same applies to an object that is copied into the graphics memory with the help of hardware routines, but without being managed completely autonomously by the hardware; here it is a BOB ( B litter Whether ject) or MOB ( M ovable O bject B lock).

In 3D games, the term sprite is sometimes used for flat objects with an animated texture . This is almost a software sprite in the classic sense, but it is inserted into the 3D scenery as a flat 3D object using 3D graphics routines.

functionality

The sprite is inserted by the graphics hardware ( graphics processor ) at the time of display at the desired position in the image. The content of the graphics memory is not changed - in contrast to the MOB or BOB, graphics data do not have to be copied over and over again. By relieving the main processor, sprites hardly use system resources and at the same time are easy to program.

The graphics data for the sprites are made available using the same method as the graphics data for the normal image structure - the C64 and the Amiga are examples , where this is done by DMA memory accesses by the graphics processor to special areas of the main memory.

The control data for the sprite display (especially the screen position) are either stored directly in the registers of the graphics hardware (example: C64, width and height of the sprites are fixed) or in special RAM areas that this hardware can access quickly enough . An example of the latter variant is the Amiga, in which the control data is transferred from the memory together with the graphics data using the DMA process. In contrast to the C64, the amount of Amiga sprites is not limited.

To move a sprite it is sufficient to simply change its x and y coordinates in the control registers; the complicated calculation of the address in the graphics memory is no longer necessary, which also relieves the main processor. The graphics processor automatically inserts the sprite at the specified coordinates when building the next image. Animated sprites are also possible; all that is needed is to replace the data of the sprite graphic in the memory with that of the next single image. Possibly. You can also simply specify a different storage area for the next single image.

A sprite is basically rectangular. Irregularly shaped sprites are also possible by making the edge transparent - either by a certain color, which is displayed transparently by the graphics processor, or by a mask that defines where the sprite should be opaque and where it should be shown transparent .

Importance for computer games

A simple C64 game with several sprites

The emergence of sprites in the 1980s revolutionized the possibilities of computer games, since at that time the processor power was insufficient to move complex graphic data on the screen (see also home computers , e.g. C64 , Amiga ). The sprites were replaced by shapes ( C16 ) or supplemented ( C128 ) or supplemented by BOBs (Amiga).

Another enhancement for computer games was sprite-sprite collision detection. As soon as the graphics processor detects that two sprites are overlapping when creating the image, this is communicated to the software via interrupt , flag or event . This means that most computer games are comparatively easy to program because the program does not have to worry about collision detection and does not use any computing power for this. A reasonable collision detection is available in almost all graphics processors, which can also handle BOBs or sprites.

Sprites are related to tiles, which are also called tile graphics . In many 2D games such as jump 'n' runs both techniques are used in parallel. Tiles are also small graphic elements. The game world is put together from them and they form walls and platforms, so they always stay in the same place. This saves working memory, since repeating patterns only have to be saved once in small tile graphics, which are arranged according to a tilemap.

Software sprites

The "software sprites" or " shapes ", which are not real sprites, usually have only two things in common with real sprites: First, they are raster graphics that are moved across the screen, and second, they have non-rectangular outlines a mask or transparent areas.

The advantages of real sprites, such as the low processor load or automatic collision detection, are no longer available. The advantage of this is that there are no hardware restrictions for the number and size of the sprites, with these limits being reset by the computing time available for implementation in software.

In contrast to real sprites, the background on which the shapes are drawn has to be drawn over and over again. The fastest way to do this is to temporarily store the entire background of the scene in the memory and copy it over and over again over the last image, but this requires additional storage space. It would save storage space if the background was created over and over again for each picture, but earlier computers were too slow for that. In cases where the background can also change for each image, these considerations are of course not applicable. At most, certain optimizations for rolling scenarios are conceivable.

There are several methods for storing and displaying software sprites. They differ in the computing time required to display the sprites and the additional memory required for the identification of transparent pixels:

  • In the first method, a binary mask is defined next to the image. When linked to this mask, just like with real sprites, a pixel of the shape is only drawn if a bit is set at the corresponding point in the mask.
  • You can also use the mask to create a "hole" in the image that is in the graphics memory and then copy the image of the sprite transparently into it. "Transparent" here means that only deleted bits (0) in the image memory are replaced by set bits (1) of the shape, bits that have already been set are not deleted. Therefore you have to create a "hole" in which all bits in the graphics memory are deleted (0), where the image of the shape should later go. Otherwise the bits set for the background and shape would mix.
  • The "modern" variant is to define a transparent color (which was available at the latest with the hardware sprites of the C64). When drawing, each pixel of the shape replaces the background; only where the transparent color is used in the shape nothing is done, so the background remains unchanged. The main disadvantage of this method is that you cannot use a color in a shape, which was a certain limitation at the time when you only had 16 colors or fewer available at the same time. In addition, the necessary code for performance reasons was best to be programmed in assembler . In the early PCs, appropriate hardware support for such advanced bit blit operations (see blitter ) was rarely available.
  • For the 256-color mode, which was common on PCs in the 1990s, compressed storage of the image data was usually used for sprites . This is followed alternately by a counter for the transparent points and then the image data to be displayed. Then the transparency counter again, etc. The advantages of this method are a reduced memory requirement and accelerated generation of the display, since no additional mask is required and transparent pixels can simply be skipped. No color is “lost” either, since the transparency is saved independently of the image data.

All methods for software sprites have in common that the subsurface has to be restored because it is destroyed by the software sprites.

The simplest method to solve the problem is to temporarily save the complete background or just the point where the shape is to be, and then copy it back when a new scene is to be drawn. The background must not change during this time. For backing up and restoring multiple shapes using cutouts, the reverse order of backing up must be used when restoring. If this is not done, artifacts could occur if individual shapes overlap. Artifacts of this kind are known from mouse pointers on window-based platforms, among other things, if they were not implemented as real sprites and one of the programs running on the system has a problem.

Sprite animation

Sprite animation of a fencer from the game Wesnoth

Since the beginning of the use of sprites, for reasons of realism, efforts have been made to animate at least human characters and other living beings such as opponents, monsters, etc. Especially when depicting a human hero, it is important that the legs move when moving to the right or left on a two-dimensional screen. That is why such a figure in more modern games consists of several sprites, which are shown in quick succession like in a cartoon in order to create a flowing impression of movement. In earlier years the software Deluxe Paint (Amiga) was often used to generate these animation sprites . Today there are follow-up programs for this purpose, such as B. Cosmigo Pro Motion . At the beginning of the computer game era there were also other techniques. In the late 1970s, Atari Basketball used the very roughly depicted lateral outline of a person standing straight as a character. While "running" a straightened leg (line) flashed at regular intervals, which was copied to the figure sprite.

CSS sprites

In web design , the term sprites is used to describe graphic files that consist of several small individual graphics. These sprites are integrated into web pages via CSS in such a way that the web browser displays the required, appropriately tailored partial graphics. The purpose of this technology is, on the one hand, to reduce the overall loading time of a website by reducing server requests and, on the other hand, to prevent delays that would result from reloading - for example in the event of hover effects.

Individual evidence

  1. CSS Sprites - Saving on HTTP requests by combining background images
  2. ↑ Mark different types of references with CSS sprites

Web links

Commons : Sprites  - collection of images, videos and audio files