# Some Directx woes

This topic is 3820 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey guys! I am new to these forums and also to Directx I am currently taking a class in college about 2d game development and we are using direct x. Anyways im supposed to add a layer of bricks to this paddle ball game but I am having trouble making the bricks appear correctly. Here is the code that deals with the bricks:
#define NUMBRICKS 8;

LPDIRECT3DTEXTURE9 brick_image;
SPRITE brick[NUMBRICKS];

if (brick_image == NULL)
return 0;

for(int i = 0; i < NUMBRICKS; i++)
{
brick.x = 0;
brick.y = 0;
brick.width = 80;
brick.height = 51;

brick.x += 80;

}

for( int i=0;i <= NUMBRICKS;i++)
{

rect.left = (i % columns)*brick.width;
rect.top = (i / columns)*brick.height;
rect.right = rect.left + brick.width;
rect.bottom = rect.top + brick.height;

}

for(int i = 0; i < NUMBRICKS; i++)
{
position2.x = (float)brick.x;
position2.y = (float)brick.y;

sprite_handler->Draw(
brick_image,
&rect,
NULL,
&position2,
D3DCOLOR_XRGB(255,255,255));

}

I am really close to figuring out why its not working its just I need some fresh eyes to check it over. The main problem that happens is that only one brick will show up and then I messed around and now only a black box shows up. Any help on this matter is greatly appreciated. Thanks!

##### Share on other sites
Well, you are setting all the bricks at the same position in the first for loop. First you set x to 0, then add 80 to it. So every brick gets positioned at 80,0.

You probably want something like brick.x = i * 80;

##### Share on other sites
Quote:
 Original post by EndurionWell, you are setting all the bricks at the same position in the first for loop. First you set x to 0, then add 80 to it. So every brick gets positioned at 80,0.You probably want something like brick.x = i * 80;

Ahh yes thanks that did help however what is happening now is I have one brick image loading at the 0,0 coordinates but the rest are not loading there is just black where the images should load.

Also forgot to mention that my games screen dimensions are 640x480.

##### Share on other sites
Hi,

sprite_handler->Draw(
brick_image,
&rect,
NULL,
&position2,
D3DCOLOR_XRGB(255,255,255));

have you got these the wrong way round?

&rect,NULL,

if memory serves one is a source rect and one a destination rect if i am not mistaken. so the first brick appears because rect is correct on the texture but the rest are black due to rect being potentially off the texture. That would be my first guess at any rate.

You should only need to load the texture in once btw, dunno if you grabbed code from different places or all from the same place.

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 10
• 9
• 9
• 11
• 11
• ### Forum Statistics

• Total Topics
633682
• Total Posts
3013309
×