How do make a color transparent when using BLT in Directx 7
I’m trying to write a tile engine and need to make a color transparent so I can overlay
My tiles. Please help!
Printable View
How do make a color transparent when using BLT in Directx 7
I’m trying to write a tile engine and need to make a color transparent so I can overlay
My tiles. Please help!
After creating the surface, use this:
VB Code:
'Set the color key to black Dim Key As DDCOLORKEY Key.low = 0 Key.high = Key.low DestSurface.SetColorKey DDCKEY_SRCBLT, Key
This way, black will be the transparent color :)
If you are using 16-bit colour, take a look here:
http://www.vbexplorer.com/directx4vb/
He has code for 16 bit colour keys (that one only works in 24- and 32- bit colour).
The code I gave you uses black no matter what the color depth is, unless it's 8-bits and you have a really weird palette :p
Yea, it will work there but for other colours forget it :)
Why would you need any other colors? :D
Can anyone help my with Orthogonal tile engines. I can make nice square one, and I’ve nearly got an orthogonal engine but I’m missing something. I’m using an offset to overlap my tiles.
For example.
---------------------------------------------------------------------------
Do the first line of tiles,
Then on the next line I move the tiles along half a tile’s width so that the edges line up.
The space between lines is half a tile’s height
And move it back to the same place as the fist tile, on the third line
And so on.
------------------------------------------------------------------------------
If you didn’t understand that, don’t worry, I can’t explain anything
But when moving tiles, the movement isn’t looking right!!! :mad:
** Could someone give me a example or some theory ** :confused:
Hum, I understand why you'd use diagonal tiles for a fake 3D effect, but I can't see why you'd wanna use ortogonal tiles - you can easily simulate that with fast square tiles :)
Why am I getting... User defined type not defined.. for
Dim Key As DDCOLORKEY
Its because you didn't goto the menu in Project > References > and DirectX7 For Visual Basic Type Library.Quote:
Originally Posted by HaLLa
Why are you even using DirectDraw at all? DirectDraw is very old, and very limited in capabilities. Although still fast. DD was designed for older cards that was more for 2D than 3D. They got rid of it in DX8 but brought it back in DX9 for those who were still using DX7 just for people to use DirectDraw.
Instead of DD, use Direct3D (DX8) using a TLVertex so the Z coordinate is ignored by the computer. That way you can do nifty special effects and have more control over your 2D sprites:
VB Code:
'This is the Flexible-Vertex-Format description for a 2D vertex (Transformed and Lit) Const FVF = D3DFVF_XYZRHW Or D3DFVF_TEX1 Or D3DFVF_DIFFUSE Or D3DFVF_SPECULAR 'This structure describes a transformed and lit vertex - it's identical to the DirectX7 type "D3DTLVERTEX" Private Type TLVERTEX X As Single Y As Single Z As Single rhw As Single color As Long specular As Long tu As Single tv As Single End Type
And on top of that, you don't need no stupid multiple color keys and tons of code just to pull off transparency. In Direct3D you just set one color that you want transparent when loading a texture, and these two lines of code in the initialization so the computer knows how its gonna be transparent.
VB Code:
D3DDevice.SetRenderState D3DRS_ALPHAREF, 255 D3DDevice.SetRenderState D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL
I also have a Massive DX 2D tutorial in my signature. ;)