@Pixelator
Hello,
There are a couple of ways to do this.
Whatever area on the sprite you want transparent (background showing through) color black. And use SET SPRITE <num>,1,1. If you want the complcated way where an image appears translucent or any color seems transparent or blended read on.
Bascially, you take two images (or an image and a background) and you look at the color value of a pixel at a certain coordinate for each image. You take the separate components of the pixels (r g and b values) and give them a weight (alpha percentage). The more weight a component has for a particular pixel in one of the images, the stronger it's intensity, and the opposite applies to the other images pixel. For example - the maximum value any r g or b component can have is 255. If two images are on top of each other and you want them to blend, the total of the blend for a component is 255 which means if one image pixel component is at 255, the other has to be at zero. Or if one is at 128, the other would have to be at 127. This shift is what allows one image to be stronger than the other which controls how images are blended.
There are examples all over the internet of coding alpha blend routines. If you have DBC enhanced, using memblocks is a good way because you can convert image data to memblocks fairly easily.
If you don't have enhanced, you could write a routine to read the file format of a bitmap (fast) or you could use the POINT command and look at each pixel in an image on the screen (slow but easy). The easiest bitdepth (screen depth) to deal with is 24 or 32 bit. 16 bit is the most difficult.
Another way is to use a ready made dll (again if you have DBC enhanced). There is an excellent image manipulation package (open source) called FreeImage. It has just about everything you need to do whatever you want to an image in many formats. Here's a link:
http://freeimage.sourceforge.net/
Here's some example code blending two images in DBC. It requires freeimage.dll. After each image is drawn, press ENTER. After the two images have been drawn, they are saved to disk. They are then loaded and blended by freeimage. I put the code together quickly so it's a bit clunky, but shows you how your desired result can be achieved without you having to code your own alpha blending routine.
rem freeimage example
rem by latch
rem 8/2007
set display mode 800,600,32
cls 0
sync on
sync rate 0
cls 0
rem create two images to blend and save them to disk
ink 255,0
box 0,0,256,256
ink rgb(255,255,255),0
text 64,114,"What's Going on?"
get image 1,0,0,257,257
sync
wait key
if file exist("what.bmp") then delete file "what.bmp"
if file exist("whatnext.bmp") then delete file "whatnext.bmp"
save image "what.bmp",1
delete image 1
cls rgb(255,0,0)
ink rgb(0,255,0),0
for n=1 to 3000
dot rnd(128)+64,rnd(128)+64
next n
get image 1,0,0,257,257
save image "whatnext.bmp",1
sync
wait key
delete image 1
cls 0
rem load in the free image dll
load dll "Freeimage.dll",1
gosub fif_formats
rem initialize and version info
call dll 1,"_FreeImage_Initialise@4",0
version$=call dll(1,"_FreeImage_GetVersion@0")
print version$
rem load the bitmaps using freeimage load
bmp1=call dll(1,"_FreeImage_Load@12",FIF_bmp,"what.bmp",0)
bmp2=call dll(1,"_FreeImage_Load@12",FIF_bmp,"whatnext.bmp",0)
rem combine them and then save the new image
rem alpha between 0 and 255
result=call dll(1,"_FreeImage_Paste@20",bmp2,bmp1,0,0,120)
print result
call dll 1,"_FreeImage_Save@16",FIF_BMP,bmp2,"whatout.bmp",0
rem load the image into dbc
load image "whatout.bmp",1
paste image 1,100,100
sync
rem free resources
call dll 1,"_FreeImage_DeInitialise@0"
delete dll 1
end
fif_formats:
rem include others as needed
FIF_BMP = 0
return
Enjoy your day.