I am trying to learn DirectX7 - DirectDraw, and i believe i have the basics down after looking around at tutorials and everything, one thing i cannot figure out, is how to draw multiple Sprites using the Source Code i uploaded. I have been messing around with this source code to learn Directdraw...I can honestly say i am a BitBlt master, so i should understand any help easily.
Can someone Please explain to me how to draw more than 1 sprite in the code uploaded.
Last edited by psycopatchet69; Nov 30th, 2004 at 11:20 PM.
If someone doesnt want to look through the code and all that, at least help me with a link to an example of what i am looking for, heavily commented code is always helpful
If any of the extra code (zooming, and the background color stuff) is in your way, just delete it, i dont really need it, i was just using that file as a tutorial sort of thing....
Oh, and to tell you the truth, i dont exactly understand why your making a type, unless your planning on something a little further then what i had in mind, all i was looking for was just to be able to BLT two or more sprites onto the backbuffer at once....
Code:
BackBuffer.Blt DestRect, Ship(Facing), SrcRect, DDBLT_KEYSRC Or DDBLT_WAIT
looking at that line, in the DisplaySprite Sub, In BItBlt I would copy the line and change the variables to draw another sprite, But that doesnt seem to work for me in this example, and if you could, please explain that....
I do have yet another question, Transparency. As i said earlier, this was just learning tutorial thingy, and well, i learned from it. But what i didnt learnfrom it, was transparency. Is there an easy way to implement transparency?
If you are refering to transparency as alphablending, I believe it's unfortunately only possible using Direct3D and using TLVertex for 2D. Probably beyond your skills since you just started learning DirectX. But if you want source code anyways on it let me know.
If you are refering to transparency as removing the background color from the sprite so only the spite is blitted, look in the LoadSprite:
VB Code:
Public Sub LoadSprite(ByRef Sprite As DirectDrawSurface7, File As String, bWidth As Integer, bHeight As Integer, [b]ColourKey As Integer[/b])
[b]Dim CKey As DDCOLORKEY[/b]
Dim ddsdNewSprite As DDSURFACEDESC2
'This routine loads sprites in the FObject file and sets their colour keys
ddsdNewSprite.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT 'Set the surface description to include the Capabilities, Width and Height
ddsdNewSprite.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN 'Set the surface's capabilities to be an offscreen surface
ddsdNewSprite.lWidth = bWidth 'Set the width of the surface
ddsdNewSprite.lHeight = bHeight 'Set the height of the surface
Set Sprite = dd.CreateSurfaceFromResource("", File, ddsdNewSprite) 'Load the bitmap from the resource file into the surface using the surface description
[b] CKey.low = ColourKey 'Set the low value of the colour key
CKey.high = ColourKey 'and the high value (in this case they're the same because we're not using a range)
Sprite.SetColorKey DDCKEY_SRCBLT, CKey 'Set the sprites colourkey using the key just created
[/b]
End Sub
In bold is a little bit of the code that will help produce transparency. Now when you call it:
VB Code:
LoadSprite Ship(0).Surface(i), "vegan" & i, Ship(0).Width, Ship(0).Height, [b]vbBlack[/b]
your image's background color that was in your bitmap file (Black) will be your source color key that you want transparent. If you want more choices in colors, here are some constants you can use to replace vbblack:
VB Code:
Public Const Transparent_Black As Long = &HFF000000
Public Const Transparent_Red As Long = &HFFFF0000
Public Const Transparent_Green As Long = &HFF00FF00
Public Const Transparent_Blue As Long = &HFF0000FF
Public Const Transparent_Magneta As Long = &HFFFF00FF
Public Const Transparent_Yellow As Long = &HFFFFFF00
Public Const Transparent_Cyan As Long = &HFF00FFFF
Public Const Transparent_White As Long = &HFFFFFFFF
'or instead of a Hexadecimal value,
'use &HFF000000 + RGB(Red,Green,Blue)
And when you blit it, one of the contsants you need to use is
DDBLT_KEYSRC
VB Code:
BackBuffer.Blt DestRect, Ship(Current_Sprite).Surface(Ship(Current_Sprite).Facing), SrcRect, [b]DDBLT_KEYSRC[/b] Or DDBLT_WAIT
If you want non transparent sprites, just add Transparency As Boolean into the Sprite type and do this when blitting:
VB Code:
If Ship(Current_Sprite).Transparency = True Then
BackBuffer.Blt DestRect, Ship(Current_Sprite).Surface(Ship(Current_Sprite).Facing), SrcRect, [b]DDBLT_KEYSRC[/b] Or DDBLT_WAIT
lol easy i wish, a little over my head there, lets go aside from the code i uploaded, how do i set the transparency when i load the image? In the surf=sprite line? or where?
Add resolved to the thread titile when it is resolved.......you just made me read through a LOOOONG thread, and it seems like all your questions are answered...
PS: BltFast isn't that much faster on new GPUs. On hardware some years ago there was a big diffrence. But the new GPUs are more 3D based, and the HW vendors don't care that much about 2D anymore. So I don't think you will get that big boost by using BltFast.