This statement allows you to define a multiplexed sprite. These objects are
managed entirely by ugBASIC, and using SPRITE
as usual. A multiplexed
sprite is a composition of composite sprite where each element of the
composition is done by using a virtual sprite that, in turns, use a
real (hardware) sprite.
sprites where images are cropped, the size of a multiplexed sprite is taken
directly from the image data, and it is rounded to the underlying hardware
size (so a 32x32 monochromatic image as above will be converted into 4
hardware sprites of 24x21 pixels). So, if the hardware sprites cannot
be resized, a part of the area inside these sprites is wasted, and
that you need more than one sprite to represent a large image.
The maximum of eight hardware sprites therefore imposes a strict limit
to the number of such objects you can display on a horizontal line.
The total width of the objects must not exceed:
24*8=192 pixels (for monochrome sprites)
16*4=96 pixels (for two colors sprites)
16*2=48 pixels (for four colors sprites)
16*1=24 pixels (for eight colors sprites)
If you try to ignore this limitation, you won't get an error message,
but your multiplexed sprite will not be displayed on the screen. So
it's vital to ensure that the above restriction is respected.
The function accepts the name
of a graphic resource, among those previously
loaded. This must correspond to a single image: therefore it can be an image
or a frame of an ATLAS
or a SEQUENCE
. The system, in a completely
automatic way, will convert the resource into graphic data compatible with the
sprite format.
The command accepts a series of parameters, which can be added after the
name of the graphic resource. The EXPAND VERTICAL
parameter allows you
to double the vertical dimensions, making each pixel occupy two or more
vertical pixels. On the other hand, the COMPRESS VERTICAL
command allows
you to restore the original dimensions. The EXPAND HORIZONTAL
parameter
allows you to double the vertical dimensions, making each pixel occupy
two or more vertical pixels. On the other hand, the COMPRESS HORIZONTAL
command allows you to restore the original dimensions. Finally, it is possible
to indicate one of the colors in the palette as "transparent", and therefore
that it does not need to generate a hardware sprite. This can be useful where
the graphic resource does not use the color black, which is the standard color
to characterize the background. Due to the isomorphic nature of the language,
not all flags are usable, or have an effect, on all targets that support sprites.
The function provides additional syntax, valid for redefining a sprite already
defined. The purpose of such syntax is to modify the graphic information inherent
to a sprite already defined previously, thus being able to dynamically replace the
appearance of the sprite. In this case, it is necessary to provide a reference to
the previously defined sprite (previous
), and ensure that the graphic
characteristics (such as the number of colors) are identical.
= MSPRITE ( name flags ) = MSPRITE ( name, previous flags )
spaceshift = MSPRITE( LOAD IMAGE( "spaceship.png" ) IGNORE COLOR GREEN ) alien = MSPRITE( LOAD IMAGE( "alien1.png" ) ) alien = MSPRITE( LOAD IMAGE( "alien2.png" ), alien )
Join BASIC 10Liner Contest with ugBASIC!
An interesting competition is held at the beginning of each year: the
BASIC 10Liner Contest.
It is possible to use ugBASIC to participate in the next
"BASIC10Liner" competition, in the following categories:
MSPRITE (function) ↔ Msp
If you have found a problem with this keyword, if you think there is a bug or, more
simply, you would like it to be improved, open an issue for this example on GitHub.
Thank you!
open an issue
BACK TO KEYWORDS