1. Bitmap Transarency

--------------21706B83721C

I'm toying with the idea of doing a Tetris style game and obviously
thought of the need to do bitmap transparency.

The first routine I come up with scans through every pixel in the sprite
and only puts it if it isn't the transparent colour. This was obviously
slow and cumbersome.

Thinking back I remembered Euphoria was optimized for drawing lines of
pixels so I thought a bit more.
 _
| |_   This shape is an example of where transparency is required
|__ |  for thes hapes to interlock (bearing in mind each is grabbed as
  |_|  a rectangle and stored in a sequence).
                                                                 _
It occured to me that each shape in Tetris can be spilt into    | |_
two rectangles, which are easier and quicker to draw from a     |_  |
sequence in Euphoria.                                             |_|

I did another routine which draws the shape from the sequence using a
four coordinate map for each shape.

The results can be seen by running the testinc.ex in from attached .zip
file and trying the two diferent routines.

has anybodyt got a better routine to do transparencies, as sprites can
not always be decomposed into rectangles?

Matt Sephton
PS: zip file also at: http://www.csc.liv.ac.uk/~u5ms/Euphoria/tetris.zip
--
u5ms at csc.liv.ac.uk
http://www.csc.liv.ac.uk/~u5ms/

--------------21706B83721C

new topic     » topic index » view message » categorize

2. Re: Bitmap Transarency

re: transparent bitmaps

darn. don't have the de-compression routines to view the file. still, here's
my 2 cents worth (probably way overvalued at that).

depending on how "tranparent" the object needs to be, you could set up your
sequence like:

sprite = {     { 0,c,c,0 },
          { c,c,c,c },
          { 0,0,c,c }
          { 0,0,0,c } }

where '0' represents a transparent region, and 'c' represents a solid. you
can pre-process the sprite to remove the leading transparent regions, and
store them as an offset into the sprite, like:

     sprite1 = {    { 1, { c,c,0 } },
               { 0, { c,c,c,c },
               { 2, { c,c } },
               { 3, { c } } }

next, you remove the trailing transparent regions, as:

     sprite2 = {    { 1, { c,c } },
               { 0, { c,c,c,c } },
               { 2, { c,c } },
               { 3, { c } } }

you now can use your line routine to display the sprite:

     for i = 1 to length( sprite ) do
          -- get the offset to add to the y axis
          yOffset = sprite[i][1]

          -- get the bitmap line
          bitmapLine = sprite[i][2]

          -- don't display it if it's been completely compressed
          if length( bitmapLine ) != 0 then
               -- display the line
               draw_bitmap_line( x+i-1, y+yOffset, bitmapLine )
          end if
     end for


using this technique, you should be able to display sprites with arbitrary
borders.

this will not work if the sprite has a hole in the middle of it (like in
Jiri's "Twins" game), but you can get around that by setting up 2 sprites.
that is, the sprite:

     sprite = {     { c,c,c,c,c,c },
               { c,0,0,0,0,c },
               { c,0,0,0,0,c },
               { c,c,c,c,c,c } }

could also be represented as two overlapping sprites:

     leftSprite = { { c,c,c,c,c,c },
               { c,0,0,0,0,0 },
               { c,0,0,0,0,0 },
               { c,c,c,c,c,c } }

     rightSprite = {     { 0,0,0,0,0,0 },
               { 0,0,0,0,0,c },
               { 0,0,0,0,0,c },
               { 0,0,0,0,0,0 } }

since the compression removes most of the transparent region, the sprites
end up looking like:

     leftSprite = { { 0, { c,c,c,c,c,c } },
               { 0, { c } },
               { 0, { c } },
               { 0, { c,c,c,c,c,c } } }

     rightSprite = {     { 6, {} },
               { 5, { c } },
               { 5, { c } },
               { 6, {} } }

so it's not as inefficient as it initially looks, especially with checks for
empty sequences.

 -- David Cuny

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu