Is it possible to alpha blend sprites ?
BlitzMax Forums/BlitzMax Beginners Area/Is it possible to alpha blend sprites ?
| ||
I load my sprites with LoadAnimImage I mask off a pre-determined color in the image Q: Is it possible to control the alpha valua of a particular sprite ? eg. only that sprite is affected? Q: Are there any tutorials to show how to do this ? |
| ||
Use SetAlpha to set the alpha of all following drawing operations. So set it to what you want for this particular sprite and then reset it to 1 (or whatever you need) afterwards. Also, by alpha-blending, do you mean giving your sprites smooth edges (anti-aliasing)? If so, you can do that quite easily. Use an art package that can create and save images with an alpha channel and draw them against a transparent background. Load them as normal, but use SetBlend ALPHABLEND before drawing them. The advantage here is that there is no need to use a mask colour. |
| ||
try this tutorial http://www.2dgamecreators.com/tutorials/gameprogramming/images/T3_Images.html |
| ||
Jazzi, thanks for that - by alpha blending I'm referring of setting the alpha value of an individual sprite that takes it from solid (1) to fully transparent (0) I can anti-alias no problem in photoshop. I've never used alpha blending on sprites before (I've only tinkered with Blitz3D and not sure if it was possible?) so looking forward to using it on a 2D game I'm putting together. assari, I'll check that out - thanks. |
| ||
JazzieB is right, eg:SetBlend ALPHABLEND SetAlpha 0.5 DrawImage img1,50,50 SetBlend MASKBLEND SetAlpha 1 DrawImage img2,150,150 |
| ||
also, in terms of optimising, how much of a performance hit does alpha blending a 32bit .PNG have compared to an 8bit .PNG ? |
| ||
GfK - yeah I got it, just tried it on a single frame and looks soooo good that I'm wetting myself in anticipation of how good my animation is going to look! ;-) Just need to write some sprite animation code now that works across all my different animations. Thanks all Still curious to know your feelings on my optimising question above. I *LOVE* BlitzMax, its finally the product I wanted BlitzMax to be!! ;-) |
| ||
Don't see a point in this optimation actually. You will need to reintegrate this data into a 32bit image again as the 8bit png would only have alpha data, no color data. |
| ||
Ah, I see. Thanks Dreamora. I'm a total noob and didn't know that. |
| ||
dreamora, can you have a 24bit PNG with both color and alpha data in it ? |
| ||
24-bit implies 3 color channels 8-bit each, no alpha, unless the png image itself is, say, e.g. 16-bit with an 8-bit alpha? |
| ||
Yeah just got with proper 32 bit png (24 bit colou, 8 bit alpha) made in a proper paint package with a transparenet background and always draw with Alpha blend and it should look lush! |
| ||
You got it to work? I tried that ages ago and couldnt get the alpha channel to be used. Maby I messed up! |
| ||
Never had a problem, as Grey says, just draw against a transparent background and make sure you're saving the alpha channel as well, as I hear that one or two programs just merge the channels together so that you lose the alpha data. Load the images as normal (I always use the default flags) and make sure you have SetBlend ALPHABLEND before you draw them. |
| ||
thanks guys - brilliant info. |