my map prints out a different size.

Started by
2 comments, last by jagguy 17 years, 9 months ago
I didn't know whether to start a new thread or continue with another. If someone could tell me the protocol of further question in a thread let me know. This place has been good for me so I don't want to do the wrong thing. I am getting now the problem of reading in a map 640 X 640 pixels, with each tile 32 pixels. So I should have 200 tiles of 32 pixel X 32 pixels.. When i print out all the tiles I don't get the whole map but it looks like 2/3 of it. It looks like the map has been scaled up when reading in so i am confused, does anyone have an idea? I read in like this if (FAILED(hr= D3DXCreateTextureFromFile(g_pd3dDevice, L"grass3.bmp",&g_BackGroundFile))) return hr; i=0; for (int row=0; row < bRows; row++) for (int col=0; col < bCols; col++) { g_back.Col = col; g_back.Row = row; g_back.xMapPos =col * 32; g_back.yMapPos =row * 32; g_back.CanMoveOnTile =true; g_back.TilePixelHeight =32; g_back.TilePixelWidth =32; g_back.TileNumber =i; g_back.TileType =1; i++; } /////print out like this count=0; for (int j=0; j< screenRows;j++) for (int i=0; i< screenCols;i++) { { backRect.left=g_back[count].xMapPos ; backRect.right=backRect.left+g_back[count].TilePixelWidth ; backRect.top=g_back[count].yMapPos ; backRect.bottom=backRect.top+g_back[count].TilePixelHeight ; D3DXVECTOR3 pos2=D3DXVECTOR3( i * 32 , j * 32 , 1); g_Sprite->Draw(g_BackGroundFile,&backRect,NULL,&pos2,0xFFFFFFFF); count+=1; of course I should only get a 640 X 480 map on the screen due to the window size but it looks like it is about 380 X 400 of the actual mapsize.
Advertisement
Have you double checked your screenRows and screenCols variables to make sure that they're 15 and 20?
My projects and HGE Tutorials: My Site
Are you sure that this code does what you think?

backRect.left=g_back[count].xMapPos ;backRect.right=backRect.left+g_back[count].TilePixelWidth ;backRect.top=g_back[count].yMapPos ;backRect.bottom=backRect.top+g_back[count].TilePixelHeight ;D3DXVECTOR3 pos2=D3DXVECTOR3(i * 32 ,j * 32 , 1);g_Sprite->Draw(g_BackGroundFile,&backRect,NULL,&pos2,0xFFFFFFFF);


The pSrcRect parameter of the ID3DXSprite::Draw function is supposed to be a rectangular area within the source texture, not a description of screen coordinates for rendering. The way you are creating your backRect indicates that you are using a 640 x 480 texture, however I suspect that you are using a 32 x 32 texture and wish to use this as a tile? If that is the case you can just pass NULL.

On the other hand if you wish to use a 640 x 480 texture you either have to specify that the texture does not have dimensions that are a power of 2 (2, 4, 8, 16, 32, 64, 128, 256, 512 etc.), or resize the image. D3DXCreateTextureFromFile assumes that the texture does have dimensions that are a power of 2 and scales your image down, which could also be the reason your map is smaller than you wished.
Ok, I am using screenRows and screenCols variables and I am making sure that they're 15 and 20.

Now I didn't know the map size has to be a power of 2, and I am using a 640 X 640 map. The pSrcRect I am using is for the area of the map, not where i want it on the screen. How did you see a 640 X 480 type of map being accessed, as it looks to me a square size with tile sizes 32pixels each side.

Anyway I think the most important thing is that the 640 X 640 isn't a power of 2. If the map is scaled up to 1024 size each way then that would explain what I am getting.

How do I correct this, do I need to rescale the src it or use the D3DXCreateTextureFromFileEx instead.



This topic is closed to new replies.

Advertisement