'=========================================================================== ' Subject: TRANSPARENT SPRITE DEMO Date: 01-21-97 (00:30) ' Author: Denis Boyles Code: QB, QBasic, PDS ' Origin: FidoNet QUIK_BAS Echo Packet: GRAPHICS.ABC '=========================================================================== 'What you're talking about are transparent sprites, that is a sprite 'where the background `shows' through. The idea behind them is pretty 'simple, just `plot' the sprite `skipping' the transparent color. 'For example, in a 256 color sprite, you might make color number 0 your '`transparent' color. Then when you draw the sprite, skip over any color '0 pixels. 'For example, say I had a simple 2 color sprite laid out as follows: ' rectangular sprite ' 11111111 ' 10000001 ' 10000001 ' 11111111 'Now, we'll make color 0 the transparent color, leaving the 1 color to be 'whatever we desire. When drawn to the screen, this would make the center of 'the sprite transparent. So we could see the current screen background 'through this transparent `window'. 'For example, say the screen was filled with . characters and then we draw 'our sprite. This is what the result might look like, assuming # is a solid '`pixel'. ' ............ ' ............ ' ..########.. ' ..#......#.. ' ..#......#.. ' ..########.. ' ............ ' ............ 'In BASIC the code to actually draw the above sprite might look something 'like the following: ' FOR Y=0 TO SpriteDepth ' FOR X=0 TO SpriteWidth ' IF sprite(x,y) <> TransparentColor THEN ' PSET (x,y), sprite(x,y) ' ENDIF ' NEXT ' NEXT 'The following program illustrates the things that I have just described 'above. The program fills the screen with colored lines and then tiles the 'transparent sprite over that. The same rectangle mentioned is used and 'the effect is the colors showing through the `window' '[Cut-'N'-Save-(SPRDEMO.BAS)------------------------------------------------] 'SPRDEMO.BAS - Transparent sprite demo, Public Domain by Denis Boyles DECLARE SUB ReadSprite () DECLARE SUB DrawSprite (x%, y%, c%) DECLARE SUB DrawLines () DECLARE SUB TileSprite () DEFINT A-Z DIM SHARED sprite(8, 4) SCREEN 13 ReadSprite DrawLines TileSprite DATA 1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1 SUB DrawLines FOR y = 0 TO 199 LINE (0, y)-(319, y), y NEXT END SUB SUB DrawSprite (x, y, c) FOR yct = 0 TO 3 FOR xct = 0 TO 7 IF sprite(xct, yct) <> 0 THEN PSET (x + xct, y + yct), c END IF NEXT NEXT END SUB SUB ReadSprite FOR y = 0 TO 3 FOR x = 0 TO 7 READ sprite(x, y) NEXT NEXT END SUB SUB TileSprite FOR y = 0 TO 199 STEP 4 FOR x = 0 TO 319 STEP 8 DrawSprite x, y, 7 NEXT NEXT END SUB '[Cut-----------------------------------------------------------------------] 'Now if you want to `move' your transparent sprite around then you need to 'do a few more things. Firstly copy the current screen are that will be 'affected to a buffer. Then draw your sprite on the screen, then `erase' it 'by restoring screen from the save buffer. 'You can use the GET and PUT commands to save and restore the background for 'you. I've whipped up another little demo that that a transparent 'sprite around the screen. The screen is filled with `stars' and some text, 'then the sprite is moved in a circle pattern until a key is pressed. 'The main loop uses a GET command to save the current `background' then 'draws the sprite. Afterwards, the screen area is restored by using a PUT 'command. Probably not the best example since there is `flickering' it does 'illuastrate the concept. Watch as the ship moves and notice that the 'background isn't affected.