-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|32|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
SoCoder -> Snippet Home -> Graphical Effects


 
Andy_A
Created : 23 February 2008
 
System : Windows
Language : Blitz

Alpha Sprites

Realtime alpha blended sprites

Here's a simple to use alpha-sprite routine.

Routine originally posted by 'ford escort'
https://www.blitzbasic.com/codearcs/codearcs.php?code=913

I've made a few optimizations to decrease time it takes to read the sprite image into a 'bank' and to decrease the time it takes to write the 'alpha-blended' sprite.

Have also included a simple demo to see how it should work.

Should be able to handle multiple alpha-sprites. Keep the images down to 64x64 pixels maximum for best results.

Andy


 

Comments


Sunday, 24 February 2008, 06:41
Jayenkai
Nicely done.
Plenty of work to get it done, though. Such a shame that Blitz doesn't natively do all that in the first place.

Either way, a neat effect if you need a certain limited amount of transparent stuff on screen. (like flickering flames, or things like that.)

In fact, it'd probably be even more useful for overlaying sprites atop one another whilst loading.

eg, you could have a preset "Shadow" transparency element, then load a single bitmap and generate an entire of wall/shadow tilemap from it.

v-- Click to enlarge for illustrated explaination! --v


Essentially, if I'd have used this method whilst making my Oh Mummy remake, I could've generated an infinite number of randomly colored base tiles, and then generated the tilemaps ingame quite easily, per level. This could've lead to hundreds of color-combo levels, rather than just having the 6 colored tilemaps I'd pre-generated.


Either way, could come in handy!
Sunday, 24 February 2008, 07:54
Andy_A
Thanks Jayenkai!

I think there's a better way to simulate different tiles on the fly. I'll post the particulars in a separate thread. :

[Edit]
Whoops! My bad. The way your illustration indicates would definitely be faster.

[Edit]
Okay then here's a technique you can use in to generate a nearly infinite number of colored tiles in a game.

Create a base tile which you use to overlay the alpha'd shadows/textures. Then using the "Fast Color Replacement" algo (https://socoder.net/index.php?snippet=12528), you generate a working copy of the "base" tile with overlays with any color you want!