Jump to content
  • Advertisement
Sign in to follow this  
xM1k3x

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.

If you intended to correct an error in the post then please contact us.

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];

	brick_image = LoadTexture("brick.bmp", D3DCOLOR_XRGB(255,0,255));
	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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
Quote:
Original post by Endurion
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;



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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!