Direct3d 2d graphic problem

Started by
5 comments, last by Dave Hunt 18 years, 10 months ago
Hey everyone, so I FINALLY started programming again after a bit of a hiatus. I am starting a 2d pong game (for kicks and giggles). However I've run into a problem. I'm trying to use one BIG graphic with all the tiles on it, and then break up all the tiles into smaller graphics. My big graphic (shown below): Image Hosted by ImageShack.us is 208 x 150. My first paddle should be 29 x 75. However when I do the dimensions in C++ it is wrong! Here's a snippet from my code:

		RECT P1;
		P1.left = 0;
		P1.right = 48;
		P1.top = 0;
		P1.bottom = 120;

		gSprite->Begin(D3DXSPRITE_ALPHABLEND);

		// build the translation matrix
		D3DXVECTOR2 trans=D3DXVECTOR2(0.0f,barP1y);
		D3DXMATRIX mat;
		D3DXMatrixTransformation2D(&mat,NULL,0.0,NULL,NULL,NULL,&trans);

		// set the transform
		gSprite->SetTransform(&mat);

		// draw to the screen
		gSprite->Draw(gTexture, &P1, NULL, NULL, 0xFFFFFFFF);



can someone tell me what is wrong, with the image or the code?
Advertisement
does it actually render an image from that textur, and the RECT is just off, is it not rendering, or does it get an error?

try D3DCOLOR_RGBA(255,255,255,255); instead of 0xFFFFFFFF
other than that, make sure that gtexture is loaded properly
These tears..leave scars...as they run down my face.
Quote:Original post by -justin-
My first paddle should be 29 x 75.

RECT P1;
P1.left = 0;
P1.right = 48;
P1.top = 0;
P1.bottom = 120;


not sure what you meant by the last post...

but yea, the rectangle is off... not sure why :/

i'll try what you said, thanx :)
I believe he meant that if your first paddle is supposed to be 29x75, and P1 is your first paddle, then it looks like you've made that paddle 48x120 instead.
yes i know, but that is my problem...

i should define it as 29x75... however, for whatever reason, if i define it like that then it comes up short (it doesn't show the whole image, just a small piece of that) only when i use 48x120 do i get the WHOLE image!
Your image is probably being resized to a power of 2 when it's loaded, in this case 256x256. That would throw off your coordinates. You should make your master image dimensions powers of 2 so that the resizing doesn't occur. You can just fill any unused space with your background/transparent color.

This topic is closed to new replies.

Advertisement