# Nwbish Direct X 7 question...

## Recommended Posts

I am using Visual Basic and trying to make a game...I made a sheet of sprites with the intended "transparent color" to be black...i have a few questions: 1) how do i tell the computer "ONLY RECOGNIZE THIS SPRITE" if it is on the sheet? Someone I know said: you have to assign a rect shape and then do rect.top rect.left rect.right and rect.bottom that tells it what to get from the spriteimage so does he mean that I need to define the top, bottom, etc. on the pic. or of a shape on the picture or...? 2) how do i make the color black transparent? Please help... -Ajain

##### Share on other sites
1) He means the corners of a rect around one frame on the sprite "sheet". For example, if your entire sprite animation is on a 128x128 texture where each frame of animation on this texture is 32x32 lined up left to right, then the rect for frame 1 would be:
rect.top = 0;rect.bottom = 31;rect.left = 0;rect.right = 31;
And rect the rect around frame 2 would be:
rect.top = 0;rect.bottom = 31;rect.left = 32;rect.right = 63;
And so on, until you've got one rect for every frame represented on that one sprite "sheet".

2) I never worked with DirectX 7, so I don't know much about DirectDraw. But I think it has something to do with colorkeying. Take a look at the COLORKEY parameter of one of the DirectDraw rendering or blitting functions (or whatever).

##### Share on other sites
could u give me a small block of example code (using the same sprite sheet idea thinger u had)?

I'm confused...

do you need to make a shape??

0.o

-Ajain

##### Share on other sites
I can't give you a code example, and tutorials I found on the web are boring.

When you display a sprite, what it actually does it just copying pixels. In order to copy pixels, you need to specify the coordinates and dimension of the source and destination surfaces. Which really mean specifying which part of the image to be copied from and where should it be copied to. This is done by specifying two rectangular areas (RECT), one for source surface, the other for destination surface.

If you still don't understand, search the web for "blit" or "blitting"

Here's from MSDN.

Oh look, GameDev.net dictionary!

thx

##### Share on other sites
I'm getting truly agrivated at this and am willing to just clip up the sprite sheet in to many different single-sprite sheets...

i have just 1 question

how do u set transparent colors??!

i'll run a few more searches...

-Ajain

##### Share on other sites
Aparently there isn't (i looked and looked and looked)...so then tell me...is there any way to just set the corner pixels and use that without 12 lines of before-hand coding???

-Ajain

##### Share on other sites
Quote:
 Original post by AjainI'm getting truly agrivated at this and am willing to just clip up the sprite sheet in to many different single-sprite sheets...i have just 1 questionhow do u set transparent colors??!i'll run a few more searches...-Ajain

What your looking to do is called color keying in DirectX 7. You need to first get the pixel format, setup a bitmask for the color you want, then set the surfaces color key. I'm not sure how you would do this in VB, but heres some C code which may help you at least find what your looking for.

DWORD          KeyColor;DDPIXELFORMAT  ddpf;DDCOLORKEY     key;// Get the pixel format.ddpf.dwSize = sizeof(ddpf);lpDDSPrimary->GetPixelFormat(&ddpf);// Determine proper key for pixel format.// We will use a pre determined bitmask for Green (0,255,0)KeyColor = ddpf.dwGBitMask;// Set the Low and High Value, then set the surfaces colorkey // passing DDCKEY_SRCBLT indicating that source color keying// will be used, during blitting.key.dwColorSpaceLowValue = KeyColor;key.dwColorSpaceHighValue = KeyColor;dx7surface->SetColorKey(DDCKEY_SRCBLT,&key);

To make your own color key you could do this:

KeyColor = (((DWORD)(ddpf.dwRBitMask * 0.25))&ddpf.dwRBitMask)           + (((DWORD)(ddpf.dwGBitMask * 0.50)) & ddpf.dwGBitMask)         + (((DWORD)(ddpf.dwBBitMask * 0.75)) & ddpf.dwBBitMask);

Edited by Coder: source tags

[Edited by - Coder on August 4, 2004 2:46:19 PM]

##### Share on other sites
hmm...sounds just a bit above my level...

i am still trying to find a way to blit something w/o having to find/write 12 lines of coding before each object...

is there a way to just jump into it or do u need to do all the preperations first?

if u need to do all preperations b4 each sprite then is there a way i could just write a funciton for it and ifso, where could i find a tutorial that explains it in clear english (i hate tutorials...never was good at them)...

thx

-Ajain

##### Share on other sites
with the acception of the fact that i am using direct X 7 (hence--2D game...i hear its harder to do 2d w/ DX8) that site would be perfect!

but its not...

-Ajain

##### Share on other sites
Quote:
 Original post by Ajainwith the acception of the fact that i am using direct X 7 (hence--2D game...i hear its harder to do 2d w/ DX8) that site would be perfect!but its not...

Huh? I think Machaira gave you a perfect site to start. There is DirectDraw tutorial there.

I haven't used VB for a long time, but I believe this is how you set the color key, and you must do it to every surface (not every sprite) when you create it.
Dim ddck As DDCOLORKEYddck.high = 0ddck.low = 0some_surface.SetColorKey DDCKEY_SRCBLT, ddck

that set the color black as the transparent color.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628278
• Total Posts
2981785

• 10
• 11
• 17
• 13
• 9